conditional if shorthand, check if argument is null

import flash.geom.Vector3D;
class Particle
{
    var x : Float;
    var y : Float;
    var mass : Vector3D;

    public function new(x : Float, y : Float, ?mass = Vector3D):Void
    {
        this.x = x;
        this.y = y;
        this.mass = (mass!=null) ? mass : new Vector3D(1.0, 1.0, 1.0);
    }
}

the very short if conditional statment (a.k.a. "shorthand") is good to use when checking if an argument in a function could be null, or set value.

If the argument mass is given, use the argument. If the mass argument is not given create a new Vector3D;

goes on 1 line of code and is easy to read.

version #10276, modified 2011-03-08 10:50:07 by MartinLindelof