I'm trying to understand why writing both methods in a class is not allowed
public bool plus(List<String>) {return true;}
public bool plus(List<Integer>) {return true;}
I am trying to understand how this is related to type-erasing, but when I decompile the following code
public class Test<T> {
boolean plus2(List<T> ss) {return false;}
boolean plus(List<String> ss) {return false;}
boolean plus(Set<Integer> ss) {return false;}
}
I get the same when I decompile it using Java decompiler (jd)
Even when I print the byte code, I can clearly see the types.
(Looking at the SO answer that declares 'but be sure types are erased in bytecode')
Compiled from "Test.java"
public class com.example.Test<T> {
public com.example.Test();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
boolean plus2(java.util.List<T>);
Code:
0: iconst_0
1: ireturn
boolean plus(java.util.List<java.lang.String>);
Code:
0: iconst_0
1: ireturn
boolean plus(java.util.Set<java.lang.Integer>);
Code:
0: iconst_0
1: ireturn
}
source
share