I was wondering if you can suggest something here.
I would like to have 2 methods:
doSomething(List<Data>) and
doSomething(List<Double>)
Since type of parameter is the same, Java is complaining
Is there a way to somehow make this overloading happen?
Why not just name them differently:
Sadly, no. Because Java implements generics via erasure those two methods would both compile down to:
Since you cannot have two methods with the same signature this will not compile.
The best you can do is:
or something equally nasty.
This doesn't work because of type erasure. One thing you could do is to add a dummy parameter, like so:
Ugly, but it works.
As an alternative, you could give the methods different names.
Generics are only available to the compiler, at compile time. They are not an execution time construct, as such the two methods above are identical, as at runtime both are equivalent too doSomething(List).