Created
July 15, 2011 22:08
-
-
Save sarumont/1085662 to your computer and use it in GitHub Desktop.
Generics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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