My code is:-
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
Please help me out in this question. I am new to java, so learning about generics.
In this code wen I used Integer, Float, Double, String all were working fine but when I get to Byte class the compiler throws an error.
How about this?
The parameters you provide as numeric literals are of type integer, and those are automatically boxed to java.lang.Integer and that’s why a corresponding method is not initially found unless you explicitly say that your literals are of type byte.