Why I can not have both of this two methods in same class?
public double foo(ArrayList<Integer> x);
public double foo(ArrayList<Double> d);
When Java implemented generics, to make the bytecode backwards compatible, they came up with type erasure. That means that at runtime, the generic information is gone. So the signatures are really:
public double foo(ArrayList x);
public double foo(ArrayList d);
and you have two methods with the same signature.
The solution here would be not to overload the method name; name the two methods different names.
Here's the Java Generics Tutorial Page on type erasure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With