Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is static Initializer in JAVA a closure

I was wondering if static Initializer in Java as shown below is a closure which groovy built on to implement the language.

public class className{
   static{

   }
}

Thanks.

like image 952
JohnTheBeloved Avatar asked Jun 11 '26 02:06

JohnTheBeloved


1 Answers

No. That is a block. Groovy also has these.

class A {
  static {
    println "static init block"
  }

  {
    println "init block"
  }

  def closure = {
    println "closure field"
  }
}

a = new A()

The code above will print:

$ groovy Block.groovy 
static init block
init block
like image 143
Will Avatar answered Jun 13 '26 17:06

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!