Akki Gupta
Akki Gupta

Reputation: 149

Java Generics compile time error and raw types

As per jls8 doc, it is compile time error if parameterized type is not well formed..According to doc,

A parameterized type C is well-formed if all of the following are true:

  • C is the name of a generic type.
  • The number of type arguments is the same as the number of type parameters in the generic declaration of C.
  • When subjected to capture conversion (§5.1.10) resulting in the type C, each type argument Xi is a subtype of
    S[F1:=X1,...,Fn:=Xn] for each bound type S in Bi.

It is a compile-time error if a parameterized type is not well-formed.

But raw types are not well formed as per point number 2..Why is it legal to declare a variable as:

ArrayList array = new ArrayList();

Upvotes: 2

Views: 85

Answers (1)

Andy Turner
Andy Turner

Reputation: 140319

From JLS 8 Sec 4.5:

A parameterized type is a class or interface type of the form C<T1,...,Tn> ...

A raw type doesn't have the <> or any of the T parameters. Thus, it's not a parameterized type, so the rules you quote are not applicable.

Upvotes: 2

Related Questions