2
我的代碼是: -字節類不泛型工作在java中
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();
}
}
OUTPUT: -
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新手,所以要學習泛型。
在這段代碼文中,我用整數,浮點數,雙精度,字符串都工作正常,但當我到達字節類編譯器會引發錯誤。
歡迎來到Java。類名的Java約定是以大寫字母開頭,所以'Abc'。這使得他人更容易閱讀你的代碼 – 2012-07-16 19:33:52