File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assertions compilation error

 
yamini nadella
Ranch Hand
Posts: 257
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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
Posts: 257
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must use javac -source 1.4 to get the assert keyword handled correctly.
 
pallavi utukuri
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic