Java Reference
In-Depth Information
How it works…
In JavaFX, there are two ways of declaring a variable:
F def —The def keyword is used to declare and assign constant values. Once a
variable is declared with the def keyword and assigned a value, it is not allowed
be reassigned a new value.
F var —The var keyword declares variables which are able to be updated at any point
after their declaration.
There's more...
All variables must have an associated type. The type can be declared explicitly or be
automatically coerced by the compiler. Unlike Java (similar to ActionScript and Scala),
the type of the variable follows the variable's name separated by a colon.
var location:String;
Explicit type declaration
The following code specifies the type (class) that the variable will receive at runtime:
var location:String;
location = "New York";
The compiler also supports a short-hand notation that combines declaration and initialization.
var location:String = "New York";
Implicit coercion
In this format, the type is left out of the declaration. The compiler automatically converts the
variable to the proper type based on the assignment.
var location;
location = "New York";
Variable location will automatically receive a type of String during compilation because the
first assignment is a string literal.
Or, the short-hand version:
var location = "New York";
JavaFX types
Similar to other languages, JavaFX supports a complete set of primitive types as listed:
 
Search WWH ::




Custom Search