Why doesn’t it cause compilation errors? Integer
and String
are different types. And if it doesn’t matter, why do things like <T, R>
exist (if one letter can stand for any number of different types, you can just type <T>
, I figure)?
Integer
and String
are different types, but both are objects (unlike int
and char
),
so for <T, R>
each of T
and R
can be a specified type of object.
You couldn’t use <S>
instead of <T,R>
because S
would be one object, whereas <T,R>
would be 2 objects. (Although you could make a class that contains two objects as instance variables, so you could make an object that holds other objects for <S>
).
1 Like