Java: When is a static initialization block useful?

前端 未结 13 1613
时光说笑
时光说笑 2020-11-30 16:49

What\'s the difference between initialization within a static block:

public class staticTest {

    sta         


        
13条回答
  •  自闭症患者
    2020-11-30 17:12

    When you want to evaluate any certain expression while class loading time then you can make use of static block but remember:

    You must handle an exception in static block meaning you cannot throw an exception from a static block.

提交回复
热议问题