Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method overloading

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?

like image 858
James Raitsev Avatar asked Dec 17 '22 19:12

James Raitsev


1 Answers

Sadly, no. Because Java implements generics via erasure those two methods would both compile down to:

doSomething(List)

Since you cannot have two methods with the same signature this will not compile.

The best you can do is:

doSomethingData(List<Data>)
doSomethingDouble(List<Double>)

or something equally nasty.

like image 111
Cameron Skinner Avatar answered Dec 31 '22 19:12

Cameron Skinner