FileDocCategorySizeDatePackage
GenericSyntax.javaAPI DocExample2623Thu Dec 11 04:11:10 GMT 2003oreilly.hcj.tiger

GenericSyntax

public class GenericSyntax extends Object
Demonstrates Generics Syntax.

Fields Summary
Set
addresses
Constructors Summary
Methods Summary
public static voidcasting()

		List<A> listOfA = new ArrayList<A>();
		List<B> listOfB = new ArrayList<B>();
		List<C> listOfC = new ArrayList<C>();
		ArrayList<A> arrayListOfA = new ArrayList<A>();
		SomeClass<A> scA = new SomeClass<A>();
		SomeClass2<A> sc2A = new SomeClass2<A>();
		SomeClass3<A> sc3A = new SomeClass3<A>();

		// casts
		Set<A> one = (Set<A>) listOfA;
		Object two = (Object) listOfA;
		// List<A> three = (List<A>) two; // Unchecked warning
		List<Integer> intlist = (List<A>)new ArrayList<Integer>();
		List<Number> numList = (List<A>) intlist;
		List four = (List) listOfB;
		List<A> five = (List<A>)arrayListOfA;
		SomeClass six = (SomeClass) sc2A;
		// SomeClass2<A> seven = (SomeClass2<A>) six; // Unchecked warning
		SomeClass3<A> eight = (SomeClass3<A>) scA;


		// List<A> z = (List<a>) obj;

		// List<A> z = (List<A>) listOfB; 
		// List<B> z = (List<B>) listOfA; 
	
public static voidmain(java.lang.String[] args)

		casting();
	
public voidsomeManagerMethod()


	   
		ListManager<List<Integer>> integerMgr = new ListManager<List<Integer>>(new LinkedList<Integer>());
		//ListManager<List<String>> stringMgr = new ListManager<List<String>>(new LinkedList<String>());
		// ... other code.
	
public static voidsomeOtherMethod()

		Crazy<Set<List<Integer>>> crazy;
		Crazy<Set<List<Object>>> crazy1;
		Crazy<Set<List<Number>>> crazy2;
		Crazy<HashSet<List<Integer>>> crazy3;
		Crazy<TreeSet<ArrayList<Number>>> crazy4;
		Crazy<Set<LinkedList<Object>>> crazy5;
		// ... and more ...