2

I find it odd that I couldn't find anyone asking about this before. But is it impossible to use static methods in XTend??

I'm using the play framework and the controller objects require your methods to be static. So does XTend really just not support static methods and I can't use it with play(So much) now?

Other than this I haven't had any other problems mixing Play! and XTend.

Thank you for any help.

Zergleb
  • 2,212
  • 15
  • 24
  • Interesting to hear that you mix Xtend with Play. Can you give more information about it? So I can only assume what you want. I don't see why you need a static method? I assume that the normal templates instantiate for each view an instance too. – niels Nov 09 '11 at 15:31
  • Finding it odd, well since Xtend is out since a couple of days only... It isn't that odd :) – i.am.michiel Nov 09 '11 at 21:22

2 Answers2

4

The latest release has support for statics:

def static void main(String[] args) {
  println("Hello World")
}

See https://www.eclipse.org/xtend/documentation/202_xtend_classes_members.html#methods

Zergleb
  • 2,212
  • 15
  • 24
Sven Efftinge
  • 3,065
  • 17
  • 17
3

My Xtext 2.0.0 does not support static methods too. You can use the external Java Class with static fields.

".java" file:

package org.some.pack1;
  class MyClassHelper {
    static Object f1(){
      return //... ;
    }
  }

".xtend" file:

package org.some.pack2
import static extension org.some.pack1.MyClassHelper.*
class MyClass  {
  def /*static*/ f1(){
    MyClassHelper::f1()
  }
}
Lev
  • 921
  • 7
  • 15