Java Reference
In-Depth Information
Advanced Binding Topics
Some of bind options offered in this section are considerably more complex, and
in some cases due to side effects and/or limitations, should be used sparingly.
Binding and Object Literals
In JavaFX, the preferred mechanism for instantiating objects is via the object lit-
eral. Alongside variable declarations, object literals represent the second and
final binding option available for developers. We've already seen how to bind
instance variables via object literals. This is normal and expected behavior. But
in addition to binding instance variables, it's also possible to bind entire objects.
For this section, we'll first state the three possible ways in which object literals
can be bound, then follow up with concrete examples.
Object literals can be bound as a whole . In this case, a change to any of an
object's instance variables will result in the creation of a new object instance
with the recalculated values.
Individual instance variables inside object literals can be bound. When
instance variables are bound, recalculations will update the values of bound
variables but will not result in the creation of a new object instance. Again,
this is the expected way in which binding and instance variables will take place.
A combination of individual instance variables or whole objects can be
bound . In this scenario, by default, a change to any instance variable will
result in the creation of a new object except for those instance variables that
are themselves bound.
A few examples here should go a long way in illustrating the various binding
scenarios that are available to object literals and their instance variables.
Included as part of these examples, we'll demonstrate whether the bind recalcu-
lations result in the creation of a new object.
First, let's define a simple class that will be used throughout to illustrate object
literal binding.
class EmpRec {
public var name : String;
public var id : Integer;
public var label : String;
public function print() : Void {
println(" obj={label}, name={name}, id={id}");
}
init {
 
 
Search WWH ::




Custom Search