Im trying to create overloading methods in java:
private BasesResponse getResponse(List<ClassA> classA) {
...
}
private BasesResponse getResponse(List<ClassB> classB) {
...
}
But eclipse is complaining about: Method getResponse(List<ClassA>)
has the same erasure getResponse(List<E>)
as another method in type BasisInformationEndpoint.
I thought method signature is method name + parmeter list.... but how can List<ClassA>
be the same as List<ClassB>
? Doesnt make sense to me.
Java generic type erasure will make it
private BasesResponse getResponse(List classA) {
...
}
private BasesResponse getResponse(List classB) {
...
}
After type erasure it is the same for compiler.
The generic types (<...>
) are present only before compilation stage, to be used for static typing.
Once compiled, those types are "erased" and List<ClassA>
essentially becomes List
. Thus you can see that when this happens, your two functions become identical.
This is called type erasure, as has been mentioned by the commenter.
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