KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a List of objects that extend another class: List<? extends Fruit> arguments; Now, I want to invoke a method on these objects. The invoking class has a method wash for each of the classes that extend Fruit , but NOT for the Fruit abstract class: void wash( Apple a); void wash( Peach p); How can I apply the method wash to all the elements in arguments ? This DOESN'T work, as my wash methods don't accept Fruit arguments: for( Fruit f: arguments) this.wash( f); // the wash() method is not a member of Fruit Is there any way to solve this without having to make an umbrella method wash( Fruit) ? Because there are dozens of wash( ? extends Fruit) methods... . EDIT : The "invoking class" I am talking about is a visitor. And I can't alter any of the Fruit classes/subclasses. I can only program the visitor. This means it isn't possible to add the wash() method (or any other methods, for that matter) to the abstract class Fruit .
Tags (comma-separated)
Save Edits
Cancel