Java Reference
In-Depth Information
Coming Features
If you had a chance to try pre-release versions of JavaFX, you may have encoun-
tered a feature known as lazy binding . With the formal release of JavaFX 1.1,
references to this aspect of the language have been removed because it was only
partially implemented. Specifically, work has yet to be done for sequences. Plans
call for full support by the next JavaFX release. In the interim, you can experi-
ment with some of the capabilities of lazy binding, keeping in mind that it is cur-
rently not supported.
The primary difference between regular binding and lazy binding lies in how and
when updates occur. With lazy binding, an update or bind recalculation only
takes place when the variable being bound to is being accessed. Whereas with
regular binding, any change to the bound expression automatically forces an
update. The performance impact of limiting the number of bind calculations can
be important. We'll touch more on this in a moment.
Listing 4.4 highlights how these two forms of binding differ.
Listing 4.4
Comparing Lazy Binding to Regular Binding
var x : Integer = 1 on replace oldValue {
println("x: {oldValue} -> {x}")
};
var y : Integer = bind x + 1 on replace oldValue
{
println("y: {oldValue} -> {y}")
};
var z : Integer = bind lazy y + 1 on replace oldValue
{
println("z: {oldValue} -> {z}")
};
println("Starting");
println("Reading z"); println("z: {z}");
println("Modify x");
x = 2;
println("Reading z"); println("z: {z}");
The listing includes three variables. The first two, x and y , use traditional bind-
ing, whereas the third, z , uses lazy binding as specified by the bind lazy key-
word sequence. Each variable has a trigger associated with it such that whenever
its value changes, it will be printed. When this code is executed, the output vali-
dates that z , which is bound lazily, is only updated when it is being accessed via
 
 
Search WWH ::




Custom Search