Total haxe beginner here. I have class A with a public prop theX
Then l have class B with a List that currently is populated with instances of class A but it could be other types aswell. In B l have a method that needs to pull out an instance from the List and set instanceA.theX = 1; but the compiler complains that there is no such prop on A. Is’nt this how Any could be used? What could be wrong here? Thanks
What I mean is, what are you storing in the list? If you are only storing object from A you can do List<A>, or maybe the object share a parent class you could use?
In that case @RblSb’s solution would work, List<{ theX: Int }>, and you don’t need any Any in the code with this.
It also work on functions function addItem(someInstance:{theX:Int}) {.
That’s exactly how you will get a runtime error though. A safe cast like that doesn’t return null on failure, it throws an exception. Maybe you were looking for Std.downcast().