I have the following code -
{s = "Hello";} String s;
This compiles the penalty, implying that variable definitions are executed before the instance blocks. However, if I use the following code instead, it does not compile ("error: illegal direct link").
{s = "Hello"; String ss = s;} String s;
Thus, it is impossible to use the value 's' on the right side of the instruction in the instance block that comes before the variable definition. Is there any reasonable explanation for what happens behind the scenes, or is it just an unusual feature of Java?
PS I saw a similar question asked earlier, the only explanation given here is a feature of Java. I am writing this to ask the community if this is really the last word on this issue.
source share