Search code examples
expressxtendstatic-block

How do I write static blocks in Xtend?


Just like in Java:

static {

}

What should I do?


Solution

  • Extend currently doesn't support static initializers - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=429141.

    One possible workaround is to create a field you don't care about just for the side-effects of the initializer:

    static val I_AM_ONLY_FOR_SIDE_EFFECTS = {
      // Code you'd want in your static initializer
      return 0
    }