According to the theory of type erase in java, I think the following two code piece should compile to same java class so have same bytecode.
public class Generic {
private Object t;
public void hi() {
System.out.println(t);
}
}
javac Generic.java
mv Generic.class Generic1.class
public class Generic<T> {
private T t;
public void hi() {
System.out.println(t);
}
}
javac Generic.java
mv Generic.class Generic2.class
compare Generic1.class with Generic2.class, they are totally difference.
So what's wrong with my think? And how Generic compiles to bytecode?
[EDIT]
javap -v nice tip, thanks.
But I can't get a detail understanding with bytecode in short time.
I'd like to know if Generic compiles with T erase to Object.
The methods in the classes here do have the same bytecode, but bytecode is not the only thing that goes in the class file.
The class file also contains the declarations of the class and its members, including the class's superclasses and implementing interfaces, the parameter and return types of its methods, the types of its fields, etc. All of those declarations keep generics (so that classes compiled separately against this class later can be checked). So the class files are different.