No Need for Setters and Constructors in Compiled JavaFX Script

Tome el ejemplo de la pagina http://learnjavafx.typepad.com/, exactamente de: http://learnjavafx.typepad.com/weblog/2007/12/compiled-java-1.html

Lo único que hice fue pasarlo a la versión 1.2 de JavaFX, digo no es un gran a porte pero, demuestra claramente la utilidad... por favor lee el articulo original para mas información.

Gracias a Jim Weaver.

/*
 *  TriggersAndPostinit.fx - Example of using a replace trigger
 *                           to eliminate the need for a setter,
 *                           and a postinit block for some
 *                           constructor-related functionality
 *
 *  Developed 2007 by James L. Weaver (jim.weaver at lat-inc.com) 'original'
 */

class Vehicle {

    /*atributos*/
    var sporty: Boolean;
    var model: String;
    var numWheels: Integer = 4 on replace oldValue {
                if (numWheels <= 0) {
                    println("{numWheels} wheels not valid, changing to {oldValue}!");
                    numWheels = oldValue;
                }
            };

    /*init not post init*/
    init {
        if (numWheels == 18 and sporty) {
            println("Veto sporty for 18 wheeler!");
            sporty = false;
        }
    }

    /*to string*/
    public override function toString(): String {
        return "Model: {model}, Number of wheels: {numWheels}, Sporty: {sporty}"
    }

}
var corvette = Vehicle { model: "Corvette" numWheels: 4 sporty: true };
var mackTruck = Vehicle { model: "Mack truck" numWheels: 18 sporty: true };

corvette.numWheels = 0;
corvette.model = "Corvette v2010";

println("{corvette.numWheels}");
println("{corvette.model}");
println("{corvette}");
println("{mackTruck}");

Salida en consola:

Veto sporty for 18 wheeler!
0 wheels not valid, changing to 4!
4
Corvette v2010
Model: Corvette v2010, Number of wheels: 4, Sporty: true
Model: Mack truck, Number of wheels: 18, Sporty: false

Ligas útiles:
http://openjfx.java.sun.com/current-build/doc/reference/onReplaceClause....
http://blogs.sun.com/clarkeman/entry/to_init_or_not_to