Java Reference
In-Depth Information
var max1 = bind if ((a > b) and (a > c)) a else
if ((b > a) and (b > c)) b else c;
function getMax(i1: Integer, i2: Integer, i3: Integer)
: Integer {
if ((i1 > i2) and (i1 > i3)) { return i1; }
else if ((i2 > i1) and (i2 > i3)) { return i2; }
else { return i3; }
}
var max2 = bind getMax(a, b, c);
println("max1={max1}, max2={max2}");
a = 4;
println("max1={max1}, max2={max2}");
b = 5;
println("max1={max1}, max2={max2}");
c = 2;
println("max1={max1}, max2={max2}");
outputs the same values for each bound variable:
max1=3, max2=3
max1=4, max2=4
max1=5, max2=5
max1=5, max2=5
You can use the
for
expression to bind JavaFX sequences. For example, the fol-
lowing lines will create a sequence called
seq
, of length 5, where the elements
are
[0, 1, 2, 3, 4]
.
var val = 0;
function incrementVal() : Integer {
return val++;
}
var start = 0;
var end = 4;
var seq = bind for (x in [start..end]) incrementVal();
println(seq);
A change in value for either variable,
start
or
end
, will also change the bound
sequence
seq
too. Next, we'll step through changes to
start
and
end
to see how
that affects what
seq
looks like. Furthermore, because the
incrementVal()
function always returns an element with a value one greater than its previous
Search WWH ::
Custom Search