Created
September 18, 2019 11:55
-
-
Save ncannasse/d8a4161b72aeebbbb03bed72e7df842e to your computer and use it in GitHub Desktop.
Abstract Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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