0

What is the difference between:

// 1
class A<T>
class B<T> extends A

and

// 2
class A<T>
class B<T> extends A<T>

Is 1 related to the Raw Types like:

List list = new ArrayList<Integer>();

whereas 2 is a preferred form ?

jwpol
  • 1,188
  • 10
  • 22
  • Don't assume that the fact both classes have a single type variable called `T` means that Java knows "this T is the same as that T". What if it were `class B extends A`? Or `class B extends A`? What do you think T would then be for A? – Andy Turner May 30 '20 at 15:22
  • Thank you for the response. What I understand also from @Donat answer, those `T`s are completely not related, so `A` is not aware of any type parameter in `B`, and hence (correct me if I am wrong) `A` is a raw type, it holds `Object` internally. – jwpol May 30 '20 at 21:39

1 Answers1

1

The first one extends the raw type. There is no way then in B to say what type T in class A should be. T in A and T in B are unrelated.

The second one extends A<T>. So T in A and T in B refer to the same type.

Donat
  • 4,157
  • 3
  • 11
  • 26