Do you speak Java?

piątek, 4 grudnia 2009

JavaFX static members

Some time ago I have read post about 10 interesting things in JavaFX Script. This post was really nice and I have learned that there is build in support to format Dates  But one point  interested me at most,

No support for static functions, variables and constants

I have already made a comment under post on this point but I would like to make it crystal clear.
There IS support for static members in JavaFX Script. Thats true - there is no "static" key word build in the language, but still you can make function or field static. We just have to put it inside class file but outside class declaration.
I.E.
public class MyClass{
  public function memberFunction(){
  }
}

public function staticFunction(){
}

var staticVar;

def STATIC_CONST; 

and thats it. You can call/access them with:
MyClass.staticFunction();
MyClass.staticVar;
MyClass.STATIC_CONST;
It is that easy! maybe not to intuitive for Java developers but still it is not so bad idea - I like it. Do you ?

Brak komentarzy: