Forcing two parameters of a generic method to have the same concrete type
You can't, basically. There's no way of doing that. Even if you could do it for a simple call to prohibit arguments of different types, it could always be bypassed using a cast:
equals((Object) date, (Object) string)
If you're interested in the execution-time types of the arguments, you can only test that at execution time. There's no way of the compiler knowing whether an argument of type Date
has a value which is a reference to precisely a java.util.Date
or some subclass.