Skip to content

Instantly share code, notes, and snippets.

@ncannasse
Created September 18, 2019 11:55
Show Gist options
  • Save ncannasse/d8a4161b72aeebbbb03bed72e7df842e to your computer and use it in GitHub Desktop.
Save ncannasse/d8a4161b72aeebbbb03bed72e7df842e to your computer and use it in GitHub Desktop.
Abstract Array
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