I am working on a project in which I need to add a ton of objects to an ArrayList and then call specific functions in them later on. I have this part down but in my program I need to access specific instances from the ArrayList with only the parameter of the class I am looking for.
For example:
public class Manager {
public static ArrayList<O> loadedHacks = new ArrayList<O>();
public void initOs(){
loadedHacks.add(new O());
}
}
public class O {
public boolean enabled = false;
public void onEnable(){}
}
public class A extends O{
}
Then later I want to do something like this:
if(Helper.get(A.class).enabled){}
It isn’t exactly clear from your question what the actual problem is that you’re trying to solve, but if I understand correctly, what you’re trying to do is say: “object X could be of some subclass of class A. If it’s subclass B, then I want to call B.method(), which isn’t defined on A”.
In which, case you can do something like this:
EDIT: from your comment, it seems the functionality you’re looking for is slightly different. If you have as a parameter a Class, then to see if a particular object is in effect an instance of that class, use the Class.isAssignableFrom() method.