Although Integer and String are two different types, they still have a common supertype. Serializable
To check this, return T ,
static <T> T f(T a, T b) { return null; } Serializable s = f(Integer.MIN_VALUE, "...");
The compiler will allow (or output, not sure about the technical term) the most specific type. For instance,
Number number = f(Integer.MAX_VALUE, BigDecimal.ONE);
The type is now permitted by Number , because both types are subtypes of Number , as well as Serializable , as well as Object , of course.
source share