Jump to content

Setters from a subclass?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
mcallinder

mcallinder

    Newbie

  • Members
  • Pip
  • 3 posts
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
mcallinder

mcallinder

    Newbie

  • Members
  • Pip
  • 3 posts
I figured it out with this:

((Subclass) list.get(id)).setVariable(variable);

If anyone knows a simpler way, please let me know. Thanks!

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
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