I am a long time Java programmer, now almost 20 years. Since I love this language a lot, I would like to share an observation.
Consider the below code snippet:
public static final String HELLO_WORLD = "Hello" + WORLD; public static final String WORLD = "World";
When you try to compile above code, Java Compiler will raise a compilation error: “illegal forward reference.”
It’s because compiler expects the static variable ‘WORLD’ to be defined first before referencing it. In order to compile successfully, the code has to be modified to:
public static final String WORLD = "World"; public static final String HELLO_WORLD = "Hello" + WORLD;
It would be convenient to Java developers if this sort of sequencing can be eliminated. Java developers are already used to this sort of flexibility when they define methods. When you define java methods, you don’t have to follow any sequence. Methods defined at the bottom of the class can be referenced by methods in top of the class. In Java language, function calls are resolved at runtime, where as static finals are resolved in compile time – that’s what causing this inconvenience.
Advancement in technology has been progressing at an unbelievable phase making application development smarter and intelligent. Applications are getting into human’s mind and starting to read what a human is thinking and serving solutions accordingly. In this rapid advancement age, there are few things which are frozen in time. One of them is the sequencing of static variables in the Java language. Maybe time to enhance?