Java Reference
In-Depth Information
extends
clause. To specify a specific function or variable, use the
mixin
class
name with the function or variable name. This is shown in the following code.
public class My Positioner extends Positioner,
AnotherPositioner {
var offset = 10.0;
public override bound function
centerX(node: Node, within: Node) : Number {
Positioner.centerX(node, within) + offset;
}
}
Mixins may also define variables, with or without default values and triggers.
The subclass either inherits these variables or must override the variable declara-
tion. The following listing demonstrates this.
public mixin class Positioner {
public var offset: Number = 10.0;
}
public class My Positioner extends Positioner {
public override var offset = 5.0 on replace {
println("{offset}");
}
}
If a class extends a JavaFX class and one or more
mixin
s, the JavaFX class takes
precedence over the
mixin
classes for variable initialization. If the variable is
declared in a superclass, the default value specified in the superclass is used; if
no default value is specified in the superclass, the “default value” for the type of
that variable is used. For the
mixin
classes, precedence is based on the order they
are defined in the
extends
clause. If a variable declared in a
mixin
has a default
value, and the variable is overridden without a default value in the main class, the
initial value specified in the
mixin
is used.
Mixins may also have
init
and
postinit
blocks. Mixin
init
and
postinit
blocks
are run after the super class's
init
and
postinit
blocks and before the subclass's
init
and
postinit
blocks.
Init
and
postinit
blocks from the
mixin
classes
are run in the order they are declared in the
extends
clause for the subclass.
In JavaFX, objects are instantiated using
object literals
. This is a declarative syntax
using the name of the class that you want to create, followed by a list of initializ-
Search WWH ::
Custom Search