Named loops:
- outer:
- for (i = 0; i < arr.length; i++) {
- for (j = 0; j < arr[i].length; j++) {
- if (someCondition(i, j)) {
- break outer;
- }
- }
- }
Class definitions can go anywhere:
- class Test {
- public static void main(String[] args) {
- class Inner {
- void wut() {
- System.out.println("wut");
- }
- }
- new Inner().wut();
- }
- }
There is an Object called Void
Void (Java Platform SE 7 ) - (Common use case is for generic methods which need not return a value)
Double bracing Lists allows you to declare and initialize without Arrays.asList()
- List<String> places = new ArrayList<String>() {
- { add("x"); add("y"); }
- };
Static methods can be generic
- class Test {
-
- static <T> T identity(T t) {
- return t;
- }
-
- public static void main(String[] args) {
- String s = Test.<String> identity("Hi");
- System.out.print(s);
- }
- }
You can supply variable length params
void example(String...strings) {};
Joint-union in generic type params
public class Baz<T extends Foo & Bar> {}
Define, instantiate, and call all at once
- new Object() {
- void hi(String in) {
- System.out.println(in);
- }
- }.hi("weird");
No comments:
Post a Comment