私が次のものを持っているとしましょう:
List<Apple> myList = new ArrayList<Apple>();
そして、私が呼び出したい場合、Javaは、他のタイプではなく、タイプを持つmyList.add(myApple)
ことを期待します(もちろんサブクラスを除く)。しかし、オブジェクト()が必要で、メソッドのオーバーロードなしで内部で宣言されたタイプに応じて異なるメソッドシグネチャを使用したい場合はどうなりますか。そのようです:myApple
Apple
Blender
<>
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's are permitted
出来ますか?