JavaFX variables and functions have a different place than traditional Java syntax.
First, variables and constants
1. Statement
var variable name: type = variable value;
DEF constant name: type = constant value;
Where the: type is optional and the compiler automatically determines the type.
var I:integer = 12;var I1 = 11;//automatically judged as Integer
def name:string = "Hello"; def name1 = "Hello";//automatically judged as String
The constants declared by DEF cannot be modified after they are assigned, but if the constant is an object type, his members can change, for example:
def P:person = new Person (); p. Name= "renamed";//can modify members
2, type
In JavaFX, there are three types of variables and constants:
Script level
Members of a class
Temporary variable in a function or block
3. Visibility
Package |
Variables can only be accessed within a defined package. |
Protected |
A variable can be accessed within a defined package, or as a subclass of a defined class. |
Public |
Variables can be accessed arbitrarily. |
Public-read |
Variables defined by Var can be accessed arbitrarily. |
Public-init |
Variables that are defined by Var can be initialized or read-access-free. |
4. System Predefined variables
__file__ represents the URL that currently loads the __file__ script.
__dir__ represents the URL of the directory where the __dir__ script is currently loaded.
__PROFILE__ returns "mobile", "desktop" or "browser" depending on the environment in which it is run
Second, function
1, the definition of the function
Function name (parameter name: argument type, ...). ): return type {
function body
}
The return type can be Void or any other type if it is not specified: return type, the system will automatically judge according to the type returned if there are no returns statements, the system defaults to return null void the first letter is uppercase