14 Replies Latest reply: May 28, 2009 4:11 PM by 807588 RSS

    Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)

    807588
      Hi there,

      I am getting the following message when trying to compile an existing project:
      LogOutAction.java:48: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
      (try -source 1.4 or lower to use 'enum' as an identifier)
      Enumeration enum = session.getAttributeNames();


      Now I did some research and people were saying that if I set my class_path to my 1.4 jdk this would be elminiated. So I pointed my class_path to jdk 1.4 and my JAVA_HOME on windows to my jre1.4 but I am still getting this error when complng the project with ant.

      Can someone please let me know what I am doing wrong?

      Cheers,
      Rob
        • 1. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
          807588
          Just rename your variable, comrade:
          Enumeration emu = session.getAttributeNames();
          • 2. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
            807588
            BigDaddyLoveHandles wrote:
            Just rename your variable, comrade:
            Enumeration emu = session.getAttributeNames();
            I appreciate the reponse, but I really like to understand what the message means to "try -source 1.4" which I am trying to achieve but have no clue how to compile with 1.4 jdk.
            • 3. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
              807588
              in version 1.5, enumerated types were introduced and enum became a keyword:
              enum Taste {SWEET, SOUR, BITTER, SALTY, UMAMI};
              Prior to that enum was not a keyword and could be used as a variable name. A similar thing happened to assert going to 1.4.
              • 4. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                807588
                Better off changing the variable name. You may also lose other functionality in other places in your code.
                • 5. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                  807588
                  Again, I appreciate everyone's feedback and understand that the API changed in 1.5. My primary question is how to build this thing with 1.4 not just to circumvent this error. the migration environment will be on 1.4 and I am trying to see how I can prevent other errors and gain a deeper understanding as of how to use different jdks.

                  So please help me understand how to compile with jdk1.4 which I assume theerror message is telling me to do.
                  • 6. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                    807588
                    rob66 wrote:
                    Hi there,

                    I am getting the following message when trying to compile an existing project:
                    LogOutAction.java:48: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
                    (try -source 1.4 or lower to use 'enum' as an identifier)
                    Enumeration enum = session.getAttributeNames();


                    Now I did some research and people were saying that if I set my class_path to my 1.4 jdk this would be elminiated. So I pointed my class_path to jdk 1.4 and my JAVA_HOME on windows to my jre1.4 but I am still getting this error when complng the project with ant.

                    Those people were idiots. You should undo that bad advice.

                    To compile for a previous version you just need to follow the instructions that javac told you.

                    Example
                    public class Test{
                    
                      private String enum;
                    
                    }
                    javac Test.java
                    Test.java:3: as of release 5, 'enum' is a keyword, and may not be used as an ide
                    ntifier
                    (use -source 1.4 or lower to use 'enum' as an identifier)
                      private String enum;
                    So do this
                    javac -source 1.4 Test.java
                    And it will compile, you will still get a warning and (worse) you will be unable to use Generics. But it will compile.

                    The most correct answer to this question is this, you should change the name.
                    • 7. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                      807588
                      rob66 wrote:
                      Again, I appreciate everyone's feedback and understand that the API changed in 1.5. My primary question is how to build this thing with 1.4 not just to circumvent this error. the migration environment will be on 1.4 and
                      That, honestly, is a mistake.
                      So please help me understand how to compile with jdk1.4 which I assume theerror message is telling me to do.
                      For your future reference

                      [http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html]
                      • 8. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                        807588
                        rob66 wrote:
                        My primary question is how to build this thing with 1.4 not just to circumvent this error. the migration environment will be on 1.4 and I am trying to see how I can prevent other errors and gain a deeper understanding as of how to use different jdks.
                        Enough people have already shook their fingers at you, so I don't feel the need to as well. Instead a comment:

                        if you want to build a project with 1.4, don't use a later version and "-source 1.4 -target 1.4". Why not? It doesn't work very well. If your code uses classes introduced after 1.4, or methods added to existing classes after 1.4, it will still compile.

                        The solution is simple. If your target environment is 1.4, develop in 1.4. Get a 1.4 JDK and party like it's 1999. (Actually, that would make it 1.2)
                        • 9. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                          807588
                          javac -source 1.4 Test.java
                          And it will compile, you will still get a warning and (worse) you will be unable to use Generics. But it will compile.
                          Ok thank you, I am using ant however not just javac from command line, so having set the classpath to 1.4 why doesn't it automatically use 1.4 to build it correctly? and how do I ensure that it does.

                          Cheers,
                          Rob
                          • 10. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                            807588
                            BigDaddyLoveHandles wrote:
                            rob66 wrote:
                            My primary question is how to build this thing with 1.4 not just to circumvent this error. the migration environment will be on 1.4 and I am trying to see how I can prevent other errors and gain a deeper understanding as of how to use different jdks.
                            Enough people have already shook their fingers at you, so I don't feel the need to as well. Instead a comment:

                            if you want to build a project with 1.4, don't use a later version and "-source 1.4 -target 1.4". Why not? It doesn't work very well. If your code uses classes introduced after 1.4, or methods added to existing classes after 1.4, it will still compile.

                            The solution is simple. If your target environment is 1.4, develop in 1.4. Get a 1.4 JDK and party like it's 1999. (Actually, that would make it 1.2)
                            And that's what I did downloaded jdk 1.4 and jre1.4 , ran the ant comand to build but got the error, so the question is why is my 1.4 not being recognized.

                            Could it be a setting in my ant programm that I need to set to let it know which jdk to pick up?

                            Thanks,
                            Rob
                            • 11. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                              jschellSomeoneStoleMyAlias
                              rob66 wrote:
                              Again, I appreciate everyone's feedback and understand that the API changed in 1.5. My primary question is how to build this thing with 1.4 not just to circumvent this error. the migration environment will be on 1.4 and I am trying to see how I can prevent other errors and gain a deeper understanding as of how to use different jdks.

                              So please help me understand how to compile with jdk1.4 which I assume theerror message is telling me to do.
                              Step 1: Uninstall the java version that you are currently using.
                              Step 2: Get a 1.4 VM/compiler.
                              Step 3: Install it.
                              Step 4: Compile your code.
                              • 12. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                                807588
                                ant: "setting the global build.compiler property, which will affect all <javac> tasks throughout the build"

                                [http://ant.apache.org/manual/CoreTasks/javac.html]

                                EDIT: or point JAVA_HOME to your 1.4 JDK. This will cause ant itself to run under 1.4
                                • 13. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                                  807588
                                  jschell wrote:
                                  Step 1: Uninstall the java version that you are currently using.
                                  One may want to retain the current JDK and have multiple ones installed.
                                  • 14. Re: Getting error: (try -source 1.4 or lower to use 'enum' as an identifier)
                                    jschellSomeoneStoleMyAlias
                                    rob66 wrote:

                                    And that's what I did downloaded jdk 1.4 and jre1.4 , ran the ant comand to build but got the error, so the question is why is my 1.4 not being recognized.

                                    Could it be a setting in my ant programm that I need to set to let it know which jdk to pick up?
                                    Presumably you also installed it.

                                    But yes that means that your ant environment is wrong.