Skip to content

Instantly share code, notes, and snippets.

@benve
Last active December 19, 2015 05:49
Show Gist options
  • Save benve/5907413 to your computer and use it in GitHub Desktop.
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
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