Is it possible to change a methods signature in Java depending on the parameter?
Example:
Given a class, with a generic parameter MyItem<T>
.
Assume this class has a method, which returns T
Given a second class 'myReturner()' which contains method myreturn(MyItem<T>)
.
Question:
Can i make myreturn(MyItem<T>)
return a T object, depending on the generic parameter of MyItem?
I suppose it is not possible, because the signature is set during compile time in Java, and T is not known at compile time. If so, what is the best way to simulate a method, which will return different objects, depending on parameter? Is writing an own method for each parameter type the only way?