3/14/2007

Are generics fully functional...?

Consider the snippet,

Vector <String>strObject = new Vector <String>();
strObject.add("STR1");
strObject.add("STR2");


Now adding an int or any other type of object into this collection would throw a compile time error, which sounds good...!
//strObject.add(12) -- Compilation error

On the other hand,
Vector newVector = strObject;
newVector.add(12);

This doesn't throw any compilation errors rather, you see a warning to recompile with -Xlint, which many a times we ignore....!

No comments:

dzone.com