When you use a collection without generics, the collection will accept Object , which means everything in Java (and will also give you Object if you try to get any of this):
List objects = new ArrayList(); objects.add( "Some Text" ); objects.add( 1 ); objects.add( new Date() ); Object object = objects.get( 0 );
After using generics, you limit the types of data that a collection can store:
List<String> objects = new ArrayList<String>(); objects.add( "Some text" ); objects.add( "Another text" ); String text = objects.get( 0 ); // the collection knows it holds only String objects to the return when trying to get something is always a String objects.add( 1 ); //this one is going to cause a compilation error, as this collection accepts only String and not Integer objects
Thus, the limitation is that you force the collection to use only one specific type, and not all, as if you had not defined a common signature.
source share