Java generic boundary type
Are the following two signatures the same?
public static <T> void work(Class<T> type,T instance);
and
public static <T,S extends T> void work(Class<T> type,S instance);
Solution
No, the two signatures are different From Java language spec, Chapter 8:
Because your two methods do not share the same number of type parameters, the signatures are different
In the actual case of calling methods with implicit type parameters, they may be considered interchangeable But this is only at the source level, never at the binary level In other words, if you have a type parameter version of work () in class Foo and it is called by a method in class bar, then switch to the two type parameter versions of work () and recompile. Well, you still need to recompile
edit
@Onepotato asked:
There is a difference between the two signatures, and the two signatures conflict (it is "beyond equivalence") Two signatures conflict if one is a sub - signature of the other It will be explained later in the same section: