According to Orcale’s Java7 assert guide:
- source mode 1.3 (default) — the compiler accepts programs that use assert as an identifier, but issues warnings. In this mode, programs are not permitted to use the assert statement.
- source mode 1.4 — the compiler generates an error message if the program uses assert as an identifier. In this mode, programs are permitted to use the assert statement.
I wrote such class:
package mm;
public class ClassTest {
public static void main(String[] arg) {
int assert = 1;
System.out.println(assert);
}
}
It should compile fine if Oracle’s info right (1.3 is default source mode). But I got errors like this:
$ javac -version
javac 1.7.0_04
$ javac -d bin src/mm/*
src\mm\ClassTest.java:5: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
int assert = 1;
^
(use -source 1.3 or lower to use 'assert' as an identifier)
src\mm\ClassTest.java:6: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
System.out.println(assert);
^
(use -source 1.3 or lower to use 'assert' as an identifier)
2 errors
I added manually -source 1.3 and it issued warnings but compiled fine. It seems that Oracle’s information is wrong and 1.3 is not default source mode. Which one is it then?
In Java 7, the default source mode is 1.7 according to Oracle’s doc (see the -source option).
The doc you’re referring to probably needs to be updated