Last active
December 19, 2015 05:49
-
-
Save benve/5907413 to your computer and use it in GitHub Desktop.
Java meno imperativo, un poco più funzionale. Aspettando Java 8. Riferimenti: http://www.perhammer.com/2008/07/java-initialising-complex-types-at.html
This file contains 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 class JavaInitialising { | |
public static void main(String[] args) { | |
String[] anArray = {"One", "Two", "Three"}; | |
List<String> aList = Arrays.asList( | |
new String[]{"One", "Two", "Three"} | |
); | |
Map<String, String> aMap = new HashMap<String, String>() { | |
{ | |
put("One", "1"); | |
put("Two", "2"); | |
put("Three", "3"); | |
} | |
}; | |
Set<String> aSet = new HashSet<String>() { | |
{ | |
add("One"); | |
add("Two"); | |
add("Three"); | |
} | |
}; | |
List<String> anotherList = new Vector<String>() { | |
{ | |
add("One"); | |
add("Two"); | |
add("Three"); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment