Java Reference
In-Depth Information
How it works...
Sequence types represent a collection of other types in JavaFX. Sequences provide a flat (depth
of one) container where you store references to other objects. A sequence is a first-class type in
JavaFX. Therefore, it has a return type and can participate in expressions.
JavaFX supports a initialization of sequence types using literal declaration which provides a
more natural way of representing the sequence. The literal expression for the sequence shows
each item in the sequence separated by a comma as shown below:
var numbers:Number[] = [10.0,5.6,12.3,0.44];
The type inference engine will attempt to determine the type of the sequence variable based
on the types of the items within the square brackets.
If all items within the bracket of the literal declaration are of the same type, the variable is
coerced into a sequence of that type. For instance, the following example, variable numbers2
is of type Integer[] :
var numbers2 = [0,2,3,4,5,6,7,8];
If items within the brackets are of different types, the inference engine will coerce the
variable to be of type Object[] . In the following code snippet, variable misc will be of type
Object[] and can receive member of any type:
var misc = [2,4.0,"messages", 5m];
Similar to Java arrays, items in a sequence are referenced using a zero-based positional index.
Sequence items are stored in order they are added (or declared) as shown in the snippet
below from ch01/source-code/src/javafx/Sequence.fx .
var q1 = ["Jan", "Feb", "Mar"];
println (q1[0]);
println (q1[1]);
println (q1[2]);
There is more...
Sequences come with several other important features worth mentioning here. Although
the literal representations of sequences looks like an array, that is where the similarity ends.
Sequences support several data management operations such as insert, union, query, and
delete. As you will see below, sequence expressions can also be used as generators in
JavaFX loops. The code samples are from script file ch01/source-code/src/javafx/
Sequence.fx .
 
Search WWH ::




Custom Search