In Haxe, is it possible to make an array readonly for other classes?

Viewed 98

We have haxe.ds.ReadOnlyArray, but it blocks push/pop for everyone. What I need is to be able to change it within a class, but not outside of it. Is it possible? When I do public var myArr(default, null):Array<Something> - it won't let other classes replace the array itself, but they can push/pop, so it's not a solution, too. Thanks!

1 Answers

You can expose it as a read-only array to the outside by using a read-only property that has a different name:

var internalArray:Array<T>;

public var publicArray(get, never):haxe.ds.ReadOnlyArray<T>;

function get_publicArray() return internalArray;
Related