Javac compile times "illegal forward references" and flaws in the Java compiler that comes with eclipse

Source: Internet
Author: User

When compiling the following class, if the switch Warning_level is assigned as "= Statusdef.warning", Javac will quote "illegal forward reference". The compiler that comes with eclipse compiles through, which is a flaw in the Eclipse compiler.

The reason for this compilation error is that the Cinit method executes each initialization snippet sequentially, in the order in which the fields are declared in the source code. For the Forwardreference class, the Cinit method performs the following functions in turn:

  1. Create a c0000_1 field with normal_level values. In the Forwardreference.class file, the initial value of the Normal_level field is written in the attribute property of the field, so before entering the Cinit method, the Normal_level field has been set to the initial value, which is 0x32 .
  2. Create a c0000_2 field with warning_level values. However, the value of the Warning_level field at this point is still 0.
  3. Set the value of the Warning_level field to statusdef.warning. As you can see, the c0000_2 created in the second step does not contain the results expected by the developer.
    public enum Forwardreference {c0000_1 (forwardreference.normal_level), c0000_2 (Forwardreference.warning_level); public static final Short normal_level = 0x32;//Toggles the following comment lines to generate an "illegal forward reference error" under Javac//public static final Short warning_level = Statusdef.warning;public static final Short warning_level = 0x08;private final short statuslevel;public short Getstatusle Vel () {return statuslevel;} Private Forwardreference (short statuslevel) {this.statuslevel = Statuslevel;} public static void Main (string[] args) {System.out.println (ForwardReference.C0000_1.getStatusLevel ()); System.out.println (ForwardReference.C0000_2.getStatusLevel ());}} Class Statusdef {Public final static short WARNING = 0x08;}

Javac compile times "illegal forward references" and flaws in the Java compiler that comes with eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.