I’ve got the following method:
protected <S> void setValue(final S oldValue, final S newValue) {
// Do something
}
I want to make sure, that both parameters are of the same type. It would be cool, if there’d be a compiler error when you try to pass parameters of two different types.
The above way is clearly not the correct one. I can put into a String and an Integer, since the both extend from Object.
Is my want even possible? Or is the only way to make sure both parameters are of the same type to check it inside the method and throw an IllegalArgumentException?
You can do that if you consider that S is the correct type :
You can and can’t input these :
or
You can do :
and use it like that
or