Vineet Bhatia
Vineet Bhatia

Reputation: 2533

How does JVM runtime maintain backward compatibility?

I have a simple Java class which uses the enum reserved keyword as a variable name. I am able to compile this code in Java 1.4 and execute it in Java 1.6:

public class Main {

    public static void main(String[] args) {
        String enum = "ENUM String";
        System.out.println(enum);
    }

}

However the Java 1.6 compiler will not compile this code because enum is a reserved keyword. Why does Java 1.6 runtime still execute this code?

Upvotes: 1

Views: 216

Answers (1)

Khoa Nghiem
Khoa Nghiem

Reputation: 315

Because when you compile your source code, it is converted into Java bytecode. So the name of your string really doesn't matter once it is compiled.

Upvotes: 5

Related Questions