java - How can I call a subclass method using a superclass object? -


i'm having issue code need call subclass method using superclass object. there possible way or work around? i'm stumped , there no helpful answer issue.

    string basiccommand = commands[0];     string advcommand = commands[1];     string percommand = commands[2];     if (objectname.get(advcommand)instanceof circle){         objectname.get(advcommand);         //.changesize(reader.converttoint(percommand)); 

advcommand of type shape superclass of class circle, , method changesize() within circle.

*data within hashmap.

you need instantiate based on classname:

  class cc = class.forname(advcommand);    circle c = (circle)c.newinstance();   c.changesize(reader.converttoint(percommand)); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -