New features in java 7

前端 未结 8 955
再見小時候
再見小時候 2020-12-02 04:14

What new features in java 7 is going to be implemented? And what are they doing now?

8条回答
  •  半阙折子戏
    2020-12-02 04:53

    Using Diamond(<>) operator for generic instance creation

    Map> trades = new TreeMap <> ();
    

    Using strings in switch statements

    String status=  “something”;
       switch(statue){
         case1: 
         case2: 
         default:
        }
    

    Underscore in numeric literals

    int val 12_15; long phoneNo = 01917_999_720L;

    Using single catch statement for throwing multiple exception by using “|” operator

    catch(IOException | NullPointerException ex){
              ex.printStackTrace();   
        }
    

    No need to close() resources because Java 7 provides try-with-resources statement

    try(FileOutputStream fos = new FileOutputStream("movies.txt");
          DataOutputStream dos = new DataOutputStream(fos)) {
                  dos.writeUTF("Java 7 Block Buster");
      } catch(IOException e) {
            // log the exception
      }
    

    binary literals with prefix “0b” or “0B”

提交回复
热议问题