FileDocCategorySizeDatePackage
TypedListExample.javaAPI DocExample1715Wed May 18 09:39:00 BST 2005com.discursive.jccook.collections.typed

TypedListExample

public class TypedListExample extends Object

Fields Summary
private List
hostNames
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		TypedListExample example = new TypedListExample();
		example.start();
	
public voidstart()

		// 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);