私のコードは次のとおりです:-
class abc<T> {
T a, b;
abc(T p, T q) {
a = p;
b = q;
}
void disp() {
System.out.println("\na = " + a);
System.out.println("b = " + b);
System.out.println("a/b is of class type : " + a.getClass().getName());
}
}
class temp {
public static void main(String...args) {
abc<Integer> a1;
a1 = new abc <Integer>(11, 22);
abc<Byte> a2 = new abc <Byte>(50,5);
a1.disp();
a2.disp();
}
}
出力:-
temp.java:23: cannot find symbol
symbol : constructor abc(int,int)
location: class abc<java.lang.Byte>
abc <Byte> a2 = new abc <Byte> (50,5);
^
1 error
この質問で私を助けてください。私はJavaが初めてなので、ジェネリックについて学びます。
このコードでは、Integer、Float、Double、String を使用しましたが、すべて正常に動作していましたが、Byte クラスに到達すると、コンパイラがエラーをスローします。