• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in assert...

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


assert can be used as an identifier in java1.3 and lower versions.
but it is not allowed to use it higher of java1.4 versions because it is a keyword.

when i am compiling above code using java1.3

javac -source 1.3 AssertTest1.java

it is giving compilation error as

AssertTest.java:6: warning: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
(use -source 1.4 or higher to use 'assert' as a keyword)
int assert;
^


why?


[ November 06, 2008: Message edited by: Ganeshkumar cheekati ]
 
Jayachandran Natarajan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ganesh,

It looks like a warning, not an Error..

Regards
Jay
[ November 06, 2008: Message edited by: Jay ]
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what should we do to remove this warning ?
[ November 06, 2008: Message edited by: Ganeshkumar cheekati ]
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well you are using a 1.4 compiler or higher. That compiler knows that assert is now a keyword. So when you use -source 1.3, it warns you (not gives error) that assert is now a keyword.

If you use actual 1.3 or older compiler, you will get no warnings.

To remove this warning you will have to change the name of the variable in main method (however than the question will be of no use)...
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eventhough i am using
javac -source 1.3 AssertTest1.java it is giving warning at compile time and finally i got output at runtime.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eventhough i am using
javac -source 1.3 AssertTest1.java it is giving warning at compile time and finally i got output at runtime


Warnings are not Errors. They are like well, Warnings !!! Just to keep you informed about some important things compiler won't held responsible?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
 
krishna pr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Giving Java -version
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic