• 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

doubt in assert...

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what should we do to remove this warning ?
[ November 06, 2008: Message edited by: Ganeshkumar cheekati ]
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try Giving Java -version
 
Hot dog! An advertiser loves us THIS much:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic