Quick question: How can I use a setter that I have in a subclass through an ArrayList? I've figured out how to access the getters i my subclass like this:
private static ArrayList<Class> list= new ArrayList<Class>();
((Subclass) list.get(id)).getVariable())
I want to be able to set a variable within the subclass... Any ideas?
2 replies to this topic
#1
Posted 16 May 2011 - 04:30 PM
|
|
|
#2
Posted 16 May 2011 - 05:27 PM
I figured it out with this:
((Subclass) list.get(id)).setVariable(variable);
If anyone knows a simpler way, please let me know. Thanks!
((Subclass) list.get(id)).setVariable(variable);
If anyone knows a simpler way, please let me know. Thanks!
#3
Posted 16 May 2011 - 11:41 PM
Nope no simpler way, unless the setVariable method you use also exists in the "Class" class, then there's no need to cast, even if subclass overrides the method.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









