Foo is a raw type

From JavaErrors

Jump to: navigation, search

You can get the error

 Foo is a raw type. References to generic type Foo<T> should be parameterized. 

if you are using a generic type without parameterizing it.

You want to parameterize your generics in almost all cases, because then you don't have to cast the things that come out of them.

WRONG

 Hashtable ht = new Hashtable();
 ht.put("one", 1);
 int i = ht.get("one");     // don't know what type the return code is

CORRECT BUT NOT BEST CHOICE

 Hashtable ht = new Hashtable();
 ht.put("one", 1);
 int i = (int)ht.get("one");     // don't know what type the return code is

CORRECT AND BETTER

 Hashtable<String, Integer> ht = new Hashtable<String, Integer>();
 ht.put("one", 1);
 int i = ht.get("one");     // yay!  no cast, yet the compiler still knows it is an Integer!
                            // (and the compiler knows how to convert from Integer to int)