JDK 7 – Project Coin is final

Friday Joseph Darcy announced through a blog post that Project Coin is final.

Project Coin is just one of the changes coming to JDK 7. But, since the changes in Project Coin are all small changes to the Java language, every single Java developer will have to deal with these coming changes.

  • It’s looking like we can use Strings in switch statements:
    static boolean booleanFromString(String s) {  
      switch(s) {  
        case "true":  
          return true;  
        case "false":  
          return false;  
      }  
      throw new IllegalArgumentException(s);  
    }  
  • Automated Resource Blocks, Josh Bloch proposed a construct like the one below:
    try (BufferedReader br = new BufferedReader(new FileReader(path)) {
      return br.readLine();
    }

    instead of:

     BufferedReader br = new BufferedReader(new FileReader(path));
     try {
       return br.readLine();
     } finally {
       br.close();
     }
  • Improved Type Inference, the diamond operator. Instead of:

    Map <String, List <String> anagrams = new HashMap <String, List <String>();

    you can do:

    Map <String, List <String> anagrams = new HashMap <>();
  • Simplified VARARG method invocation:
    static <T> List <T> asList(T... elements) { ... }
    
    static List <Callable <String> stringFactories() {
      Callable <String> a, b, c;
      ...
      *// Warning: ** uses unchecked or unsafe operations *
      return asList(a, b, c);
    }

    After this change:

    *// Warning: ** enables unsafe generic array creation *
    static <T> List <T> asList(T... elements) { ... }
    
    static List <Callable <String> stringFactories() {
      Callable <String> a, b, c;
      ...
      return asList(a, b, c);
    }
  • Something with better literal integers, can’t seem to find the details at the moment.
  • And language support for JSR 292. But this one is only interesting when dealing with dynamic languages.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>