Raw type

A raw type is define to be either:

The name of a generic type declaration used without any accompanying actual type parameters.
Any non-static type member of a raw type R that is not inherited from a superclass or superinterface of R.
Here's an example to illustrate:

public class MyType<E> {
    class Inner { }
    static class Nested { }

    public static void main(String[] args) {
        MyType mt;          // warning: MyType is a raw type
        MyType.Inner inn;   // warning: MyType.Inner is a raw type

        MyType.Nested nest; // no warning: not parameterized type
        MyType<Object> mt1; // no warning: type parameter given
        MyType<?> mt2;      // no warning: type parameter given (wildcard OK!)
    }
}
Source:


  • The raw type does not have type safety, you can add just about anything to a List.

0 comments:

Post a Comment

My Instagram