I am currently creating a class, which has a field of Object type.
My issue is that when accessing a member of this object, the compiler throws a Symbol not found error, as the class is not known at compile-time. Is there a way to ignore this, or mark it as resolve later, i.e. at runtime?
Specifically: I have a linked list that collects a list of classes, which store information about UI controls, as well as storing a reference to the real UI control (this being the Object field as obj). The Object (obj) has a hitbox member (hb), which I am trying to set a property of.
The offending line is:
items.get(this.curIndex).obj.hb.hovered=true;
As I am not at liberty to publish the source, here's a mockup for easier understanding of what's happening.
public class MenuButton {
public HitBox hb;
...
}
public class NameEdit {
public HitBox hb;
...
}
public class VolumeSlider {
public HitBox hb;
...
}
public class HitBox {
public Boolean hovered;
...
}
public class AObject {
public String label;
public String hint;
public Object obj;
...
}
public class AContainer {
public LinkedList<AObject> items=new LinkedList<>();
public void add(Object obj) {
items.add(obj);
}
...
}
//elsewhere:
public LinkedList<AContainer> containers=new LinkedList<>();
...
containers.get(0).items.get(0).obj.hb.hovered=true;
What this comes down to is that AObject has an obj member, which the compiler cannot infer the class of, thus I get a cannot find symbol, since Java cannot check at compile-time that when obj is set, it's going to have a hb field.
Any help is greatly appreciated.