How to call method of the subclass?

I have a superclass like this:

public class GenericUpdate{

//...other stuff...

public String getName(){return null;};

}

And a subclasses like this:

public class FromFriend extends GenericUpdate {

@Override
public String getName() {return getFriend().getName();}

}

or this:

public class FromArtist extends GenericUpdate {

@Override
public String getName() {return getArtist().getName();}

}

Now,

some other class delivers me a list of GenericUpdate

if I iterate on the list and call GenericUpdate.getName() I get null back from getName()

is there a nice solution to avoid this?

Thanks


EDIT EDIT EDIT EDIT EDIT

the actual instances of the GenericUpdate class are retrieved from Android Intents, they are retrieved like this:

    genericUpdate=intent.getParcelableExtra(GENERIC_UPDATE);

and they are put in the intent like this:

GenericUpdate genericUpdate=((FlowAdapter)parent.getAdapter()).getItem(position);    
//...                        
intent.putExtra(PostDetailActivity.GENERIC_UPDATE,genericUpdate);
//...


Source: oop

Leave a Reply