Skip to content

Instantly share code, notes, and snippets.

@sarumont
Created July 15, 2011 22:08
Show Gist options
  • Save sarumont/1085662 to your computer and use it in GitHub Desktop.
Save sarumont/1085662 to your computer and use it in GitHub Desktop.
Generics
public static void main( String[] args ) throws Exception {
Map<String,String> sm = new HashMap(3);
//barf1( sm ); // compile-time error
barf2( sm );
barf3( sm );
for ( String s : sm.keySet()) {
System.out.println( "key: "+s+" "+s.getClass());
}
}
public static void barf1( Map<Object,Object> obj ) {
obj.put( 1, 1 );
}
public static void barf2( Map<?,?> obj ) {
}
public static void barf3( Map obj ) {
obj.put( 3, 3 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment