I just looked through the new language features in Java 7, and experimented with them in DrJava.
None of the changes are supported in the Interactions Pane, and there will be a lot of required work to make these things work there. We’ll have to change the parser, change the type checker, change the interpreter, and so on.
There are, however, smaller changes that we should do to provide better support in the Definitions Pane:
- Binary literals
int i = 0b100000;
are not syntax-highlighted correctly. - Numeric literals with an underscore in them
int i = 1_000; double d = 3.141_5927;
are not syntax-highlighted correctly. - In some cases, try-with-resources is indented badly:
1
2
3
4
5
6
7
8
9
10// badly indented
public static void tryWithResources2(String f) {
try (InputStream is = new FileInputStream(new File(f));
InputStream is2 = new FileInputStream(new File(f))) {
is.read();
}
catch(IOException e) {
e.printStackTrace();
}
}
Everything else looks pretty good. Here’s the sample class that I used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import java.io.*; import java.util.*; public class Java7Samples { public static void main(String[] args) { stringSwitch(args[0]); intSwitch(new Integer(args[1])); tryWithResources(args[2]); tryWithResources2(args[2]); multiCatch(new Integer(args[3])); // bad integer syntax highlighting int i = 0b100000; System.out.println(i); // bad numeric syntax highlighting i = 1_000_000; System.out.println(i); i = 2__000__000; System.out.println(i); // int illegal = _1000; // int illegal2 = 1000_; double d = 123_456.789_012; System.out.println(d); } public static void stringSwitch(String arg) { switch(arg) { case "one": System.out.println("case one"); break; case "two": case "three": System.out.println("case two or three"); break; default: System.out.println("default case"); } } public static void intSwitch(int arg) { switch(arg) { case 1: System.out.println("case 1"); break; case 2: case 3: System.out.println("case 2 or 3"); break; default: System.out.println("default case"); } } public static void tryWithResources(String f) { try (InputStream is = new FileInputStream(new File(f))) { is.read(); } catch(IOException e) { e.printStackTrace(); } } // badly indented public static void tryWithResources2(String f) { try (InputStream is = new FileInputStream(new File(f)); InputStream is2 = new FileInputStream(new File(f))) { is.read(); } catch(IOException e) { e.printStackTrace(); } } public static class Ex1 extends RuntimeException { } public static class Ex2 extends RuntimeException { } public static class Ex3or4 extends RuntimeException { } public static class Ex3 extends Ex3or4 { } public static class Ex4 extends Ex3or4 { } public static void doSomething(int i) throws Ex1, Ex2, Ex3, Ex4 { switch(i) { case 1: throw new Ex1(); case 2: throw new Ex2(); case 3: throw new Ex3(); case 4: throw new Ex4(); } } public static void handleEx1Or2(RuntimeException e) { System.out.println("handlEx1Or2"); } public static void handleEx3Or4(Ex3or4 e) { System.out.println("handlEx3Or4"); } public static void multiCatch(int i) { try { doSomething(i); } catch(Ex1 | Ex2 ex) { handleEx1Or2(ex); } catch(Ex3 | Ex4 ex) { handleEx3Or4(ex); } } public static void multiCatch2(int i) { try { doSomething(i); } catch(Ex1 | Ex2 ex) { handleEx1Or2(ex); } catch(Ex3 | Ex4 ex) { handleEx3Or4(ex); } } public static Map<String, String> diamond() { return new HashMap<>(); } public static void diamond2() { Map<String, String> map = new HashMap<>(); } } |
Update