|
Spec-Zone .ru
спецификации, руководства, описания, API
|
JavaFX Script data types, hereafter called JavaFX types, describe the kinds of values a JavaFX expression can have. Every JavaFX variable, function, and expression has a type, most often determined from context. JavaFX variables can explicitly declare their type; a function can explicitly declare the types of its parameters and the type of its return value. JavaFX types (with the exception of Void) consist of an element specifier and a cardinality. The element specifier determines what the type holds and the cardinality determines how many of them can be held.
Element specifiers are classes or function signatures. Classes include both JavaFX classes and Java classes. These are some example representations of element specifiers which are classes:
MyClass java.util.Map Duration javafx.animation.Timeline Integer
A function signature consists of the parameter types and return type -- function signatures are unnamed and are not tied to particular functions which might implement the signature. These are some example representations of element specifiers which are function signatures:
function(:Number):Boolean function(:Integer,:Integer):SplotchedBall function():Integer
See Function Types for more information.
All element specifiers are subtypes of java.lang.Object.
[In formal type systems the element specifier would be called the ground type]
The cardinality of a type determines how many elements can be held in a JavaFX type. The three cardinalities are optional, required, and sequence.
Optional cardinality means there can be one element or no elements. This is the cardinality associated with most types, currently including all user defined classes. If you define a class Foo, then the JavaFX type "Foo" has class Foo as its element specifier and optional as its cardinality. For example:
var x : Foo;
Says that x can hold an instance of Foo (one element) or can hold null, the nonexistent value (no elements).
Required cardinality means there must be one element. This is the cardinality associated with the built-in types String, Integer, Number, Boolean, and Duration. For example:
var k : Integer;
Says that k holds one Integer.
The nonexistent value, null, is not a permitted value for types with required cardinality. Attempts to assign null to a type with required cardinality will be converted to the default value (see the Default Values section). Attempts to convert null to a type with required cardinality will be converted to the default value.