The reason this compiler is because Java will output the most specific supertype of passed arguments, in this case Object Serializable & Comparable<? extends Serializable & Comparable<? extends Comparable<?>>> Serializable & Comparable<? extends Serializable & Comparable<? extends Comparable<?>>> Serializable & Comparable<? extends Serializable & Comparable<? extends Comparable<?>>> , after 1 is put into a square Integer and "1" is passed as a String .
No generics:
private static void method(Number arg1, Number arg2) {
Even without generics, you can pass Integer and Double .
Only if the type in question is final , can you do this without generics:
private static void method(String arg1, String arg2) {
There is one generic edge case that I can come up with to make sure this is the exact type. If you have a final class and you place an upper bound, you can limit it to the same class.
public <T extends MyFinalClass> void method(T arg1, T arg2) {
But then you can do the same without generics.
public void method(MyFinalClass arg1, MyFinalClass arg2) {
source share