wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assertions compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assertions compilation error" Watch "assertions compilation error" New topic
Author

assertions compilation error

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257

when I tried to compile above program as
javac test1
then I got error message as
test1.java:13: warning: as of release 1.4, assert is a keyword, and may not be u
sed as an identifier
assert x < 3;
^
test1.java:13: ';' expected
assert x < 3;
^
test1.java:13: cannot resolve symbol
symbol : class assert
location: class test1
assert x < 3;
^
test1.java:13: x is already defined in asserta()
assert x < 3;
^
3 errors
-----------
when I compiled as javac -source 1.4 test1 then it is compiling and running fine with -ea and -da.
----
my version is
build 1.4.1_03-b02
(Added code tags)
[ April 20, 2004: Message edited by: Barry Gaunt ]
Leonardo FIgueiredo
Greenhorn

Joined: Apr 05, 2004
Posts: 2
//test1.java:13: warning: as of release 1.4, assert is a keyword, and may not be u
sed as an identifier
You not specified that the class is 1.4 so the compiler is supposing its 1.3 or older code. So, you can use assert as an identifier but is not advised to.

//test1.java:13: ';' expected
//assert x < 3;

test1.java:13: cannot resolve symbol
symbol : class assert
location: class test1
assert x < 3;
^
test1.java:13: x is already defined in asserta()
assert x < 3;
The code is 1.3 so assert is a normal word that can be used as a identifier. By this angle this line is wrong.
yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
So if there is assert statement in program even by JRE is 1.4 still do I need to compile like below.
c:> javac -source 1.4 test1
Can't I compile like c:>javac test1 ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You must use javac -source 1.4 to get the assert keyword handled correctly.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
if u dont compile using
c:> javac -source 1.4 test1 the default u will get is
c:> javac -source 1.3 test1
which dont accept assert as identifier so it must be compiled using
c:> javac -source 1.4 test1 and at runtime assertions are disabled so they must be enabled using
c:> java -ea test1


Thanks,<br />Pallavi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: assertions compilation error
 
Similar Threads
Regarding Package
assert - Usage
assertion doubt
doubt in assert...
assert keydword usage.