17 May 2014

Generic Constraints


public class Printer<T extends ICartridge>

Generic Method


public <T,U> void printUsingCartridge(T cartridge, U message){
	System.out.println(cartridge.toString() + message);
}

Generic Wildcards

private static void printOne(Printer<? extends ICartridge> printer){
		
}

difference between Csharp

They disappear after being compiled

that means you can not do that

T thing = new T();

and you can not check the type of T during runtime

if(myObject instanceof T) //compiler Error!

Cannot perform instanceof check against type parameter T. Use its erasure ICartridge instead since further generic type information will be erased at runtime



blog comments powered by Disqus