Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8061549

Disallow _ as a one-character identifier

    Details

    • Subcomponent:
    • Resolved In Build:
      b43
    • Verification:
      Verified

      Backports

        Description

        Complete the removal, begun in Java SE 8, of underscore from the set of legal identifier names.

          Issue Links

            Activity

            Hide
            darcy Joe Darcy added a comment -
            No known instances of using "_" as an identifier in the jdk or langtools repos, but the other repos would need to be tested.
            Show
            darcy Joe Darcy added a comment - No known instances of using "_" as an identifier in the jdk or langtools repos, but the other repos would need to be tested.
            Hide
            jlahoda Jan Lahoda added a comment - - edited
            To demonstrate the output of the current proposed patch, consider this source code:
            ---
            public interface Lambda {
                public int a(int _);
                public default void t(Lambda l) {
                    t(_ -> 0);
                }
            }
            ---

            Compiling with JDK8, this leads to:
            ---
            $ javac Lambda.java
            Lambda.java:2: warning: '_' used as an identifier
                public int a(int _);
                                 ^
              (use of '_' as an identifier might not be supported in releases after Java SE 8)
            Lambda.java:4: error: '_' used as an identifier
                    t(_ -> 0);
                      ^
              (use of '_' as an identifier is forbidden for lambda parameters)
            1 error
            1 warning
            ---

            Compiling with the proposed patch and -source 9 leads to:
            ---
            $ javac -source 9 Lambda.java
            Lambda.java:2: error: as of release 9, '_' is a keyword, and may not be used as an identifier
                public int a(int _);
                                 ^
            Lambda.java:4: error: '_' used as an identifier
                    t(_ -> 0);
                      ^
              (use of '_' as an identifier is forbidden for lambda parameters)
            2 errors
            ---

            Compiling with the proposed patch and -source 8 leads to:
            ---
            $ javac -source 8 Lambda.java
            warning: [options] bootstrap class path not set in conjunction with -source 1.8
            Lambda.java:2: warning: as of release 9, '_' is a keyword, and may not be used as an identifier
                public int a(int _);
                                 ^
            Lambda.java:4: error: '_' used as an identifier
                    t(_ -> 0);
                      ^
              (use of '_' as an identifier is forbidden for lambda parameters)
            1 error
            2 warnings
            ---
            Show
            jlahoda Jan Lahoda added a comment - - edited To demonstrate the output of the current proposed patch, consider this source code: --- public interface Lambda {     public int a(int _);     public default void t(Lambda l) {         t(_ -> 0);     } } --- Compiling with JDK8, this leads to: --- $ javac Lambda.java Lambda.java:2: warning: '_' used as an identifier     public int a(int _);                      ^   (use of '_' as an identifier might not be supported in releases after Java SE 8) Lambda.java:4: error: '_' used as an identifier         t(_ -> 0);           ^   (use of '_' as an identifier is forbidden for lambda parameters) 1 error 1 warning --- Compiling with the proposed patch and -source 9 leads to: --- $ javac -source 9 Lambda.java Lambda.java:2: error: as of release 9, '_' is a keyword, and may not be used as an identifier     public int a(int _);                      ^ Lambda.java:4: error: '_' used as an identifier         t(_ -> 0);           ^   (use of '_' as an identifier is forbidden for lambda parameters) 2 errors --- Compiling with the proposed patch and -source 8 leads to: --- $ javac -source 8 Lambda.java warning: [options] bootstrap class path not set in conjunction with -source 1.8 Lambda.java:2: warning: as of release 9, '_' is a keyword, and may not be used as an identifier     public int a(int _);                      ^ Lambda.java:4: error: '_' used as an identifier         t(_ -> 0);           ^   (use of '_' as an identifier is forbidden for lambda parameters) 1 error 2 warnings ---
            Hide
            jlahoda Jan Lahoda added a comment -
            Attaching a simple finder for underscore as one-character identifiers. Needs tools.jar on classpath. Takes a single parameter, which is the directory that should be searched.
            Show
            jlahoda Jan Lahoda added a comment - Attaching a simple finder for underscore as one-character identifiers. Needs tools.jar on classpath. Takes a single parameter, which is the directory that should be searched.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/84a76798cff3
            User: jlahoda
            Date: 2014-12-08 17:16:47 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/84a76798cff3 User: jlahoda Date: 2014-12-08 17:16:47 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/84a76798cff3
            User: lana
            Date: 2014-12-17 21:52:40 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/84a76798cff3 User: lana Date: 2014-12-17 21:52:40 +0000

              People

              • Assignee:
                jlahoda Jan Lahoda
                Reporter:
                mtrudeau Michel Trudeau
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: