I'm learning about Generics
, but I do not see the appeal of Bounded Types
.
Consider the following:
Class
A
and B
both extends abstract class Letter
, which contains a print()
method.
So the following code uses Bounded Types
and accepts instances of A
and B
.
public class LetterGeneric<T extends Letter> {
public LetterGeneric(T t) {
t.print();
}
}
The following code also accepts instances of A
and B
, but it doesn't use generics.
public class LetterNotGeneric {
LetterNotGeneric(Letter t) {
t.print();
}
}
Is there a reason to use Bounded Types
NOT demonstrated in this code? Maybe a performance difference between the two?
The websites I've looked at (1/2 for example) explain how Bounded Types
work, but fail to explain the difference between the 2 examples given.