Hi there
How can I possibly allow @:arrayAccess
(like for instance myclass[26]
) to a custom class?
I am trying to achieve this by giving my class these fields:
class MyClass {
var innerdata : Array<T>;
@:arrayAccess
public inline function get(key:Int) {
return innerdata.get(key);
}
@:arrayAccess
public inline function arrayWrite(k:Int, v:T):T { // also tried `set` as function name
innerdata.set(k, v);
return v;
}
}
Is @:arrayAccess
only possible with abstracts? (Also the manual puts it under the category for abstracts)
(Unfortunately, I can’t use an abstract instead, because then I cannot declare member variables /variable fields )
EDIT: Oh, maybe these criteria must be met somehow manual/expression-array-access? However
class MyClass<T> extends Array<T> {...}
won’t work it seems.