There is an existing Set<Trump>
that is passed on to another function that takes in a Set<? extends Politician>
as an argument. Given that Set<? extends Politician>
is going to contain either a Politician
Object or a Trump
Object only.
The Politican
Class can't be modified. The Trump
Class is available for modification.
Is there a way to cleanly do the following, or how should the derived class (Trump
) be re-designed to be able to do this?
public Set<Trump> getSetOfTrump(Set<? extends Politician> politicianSet)
{
//do some processing
for(Politician pol : politicianSet){ //compiler is ok.. but I dont need Politician Object here
}
for(Trump t : politicianSet){ // any way to get Trump Objects out of politicianSet?
}
}