Skip to content

Instantly share code, notes, and snippets.

@ncannasse
Created September 18, 2019 11:56
Show Gist options
  • Save ncannasse/9e1adbecab9d0b40ceb899fd432daf11 to your computer and use it in GitHub Desktop.
Save ncannasse/9e1adbecab9d0b40ceb899fd432daf11 to your computer and use it in GitHub Desktop.
abstract MyArray<T>(#if java java.NativeArray<T> #else Array<T> #end) {
public inline function new(size:Int) {
#if java
this = new java.NativeArray(size);
#else
this = new Array();
if( size > 0 ) this[size-1] = cast null;
#end
}
@:op([]) inline function get( idx : Int ) return this[idx];
@:op([]) inline function set( idx : Int, v : T ) return this[idx] = v;
}
class Main {
public static function main() {
var a = new MyArray<Int>(55);
a[5] = 33;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment