私は今日ジェネリックを学び始めましたが、これは私にとって奇妙なことです:
私は一般的な方法を持っています:
public<T> HashMap<String, T> getAllEntitySameType(T type) {
System.out.println(type.getClass());
HashMap<String, T> result = null;
if(type instanceof Project)
{
System.out.println(type.toString());
System.out.println("Yes, instance of Project;");
}
if(type instanceof String)
{
System.out.println(type.toString());
System.out.println("Yes, instance of String;");
}
this.getProjects();
return result;
}
そして、Tタイプのクラスを簡単に判別できます
Project<Double> project = new Project<Double>();
company2.getAllEntitySameType(project);
company2.getAllEntitySameType("TestString");
出力は次のようになります。
class Project
Yes, instance of Project;
class java.lang.String
TestString
Yes, instance of String;
ジェネリックではインスタンスを使用できないと思いました。私の知識では何かが完全ではありません。ありがとう...