@:genericclass MyClass<T> { public var value: T;
public function new(value: T) { this.value = value; }
public function resetToDefault(): Void { // Set the 'value' field to its default value // according to its compile-time type. // `0` for Int // `0.0` for Float // `false` for Bool // `null` for anything else // In C# its possible to do it like so: this.value = default(T); // invalid Haxe code // Done at compilation time with no // performance penalty at runtime. }}
On cpp, you can set them to the null-dynamic:
var i:Int = 123;
var d:Dynamic = null; i = d;
trace(i);
You could set it to null directly, but the compiler wont let you, event with "untyped", but this should work:
untyped i = __cpp__("null()");
Hugh
Another option might be to create a defaultValue member (or static, if that works with generics) an let it initialize normally, and never set it. Then just use "value=defaultValue".
Also note that on neko, the integers will start off at null, not 0.
Hugh
On cpp, you can set them to the null-dynamic:
var i:Int = 123;
var d:Dynamic = null; i = d;
trace(i);You could set it to null directly, but the compiler wont let you, event with "untyped", but this should work:
untyped i = __cpp__("null()");
Another option might be to create a defaultValue member (or static, if that works with generics) an let it initialize normally, and never set it. Then just use "value=defaultValue".
Also note that on neko, the integers will start off at null, not 0.