// Make sure that items added to this
hostNames = TypedList.decorate( new ArrayList(), String.class );
// Add two String objects
hostNames.add( "papp01.thestreet.com" );
hostNames.add( "test.slashdot.org" );
// Try to add an Integer
try {
hostNames.add( new Integer(43) );
} catch( IllegalArgumentException iae ) {
System.out.println( "Adding an Integer Failed as expected" );
}
// Now we can safely cast without the possibility of a ClassCastException
String hostName = (String) hostNames.get(0);