• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

assertions compilation error

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must use javac -source 1.4 to get the assert keyword handled correctly.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic