Say I have the following:
List<Apple> myList = new ArrayList<Apple>();
And if I want to call myList.add(myApple) , Java expects myApple be of type Apple and not others (except for subclasses, of course). But what if I want to have an object ( Blender ) and have different method signatures according to the type declared inside <> and without overloading the methods; So:
Blender<Apple> Tool = new Blender<Apple>(); Tool.blendIt(new Apple()); //expects to have only apples in here Blender<Banana> OtherTool = new Blender<Banana>(); OtherTool.blendIt(new Banana()); //only Banana are permitted
Is it possible?
Tomatoomato
source share