Why does the java compiler report only one error at a time?
•
Java
I have a clip
class T{ int y; public static void main(String... s){ int x; System.out.println(x); System.out.println(y); } }
There are two errors, but why only one error is displayed at compile time?
The error displayed is:
non-static variable y cannot be referenced from a static context System.out.println(y); ^
But what about this mistake
variable x might not have been initialized System.out.println(x); ^
Solution
The java compiler compiles code in several passes Some types of errors are detected in each pass In your example, javac does not see if x can be initialized until the rest of the code is actually passed through the previous compiler
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码