Smoking assertions?

J

jupiter

With regard to assertions it appears that the compiler default has
changed from 1.4 to 1.5. The 1.5 default compiles as-if "-source
1.5" instead of the old 1.4 way "-source 1.3".

All well and good but 1.5 doesn't appear to let me compile with
"-source 1.3" to have an identifier named "assert". Apparently you
could do this with 1.4. If I try to 1.5 compile with "-source 1.3"
it returns the error that "assert is a keyword, try compiling
with -source 1.4, blah blah".

Does anybody know if this is correct and why they removed the
ability to compile as 1.3?
 
D

Daniel Pitts

jupiter said:
With regard to assertions it appears that the compiler default has
changed from 1.4 to 1.5. The 1.5 default compiles as-if "-source
1.5" instead of the old 1.4 way "-source 1.3".

All well and good but 1.5 doesn't appear to let me compile with
"-source 1.3" to have an identifier named "assert". Apparently you
could do this with 1.4. If I try to 1.5 compile with "-source 1.3"
it returns the error that "assert is a keyword, try compiling
with -source 1.4, blah blah".

Does anybody know if this is correct and why they removed the
ability to compile as 1.3?

I have no idea, but I have a suggestion...

Search/ReplaceAll "assert" with "assert$"
 
J

jupiter

Daniel Pitts said:
I have no idea, but I have a suggestion...

Search/ReplaceAll "assert" with "assert$"

Hehehe, good one, but where is your sense of adventure?

I'm trying to figure it out because of a case of "certification
test paranoia". Nobody in their right mind would ever need to use
"assert" as an identifier, which is why my paranoia is telling me
it's almost guaranteed to be on the test.
 
H

Hemal Pandya

jupiter said:
With regard to assertions it appears that the compiler default has
changed from 1.4 to 1.5. The 1.5 default compiles as-if "-source
1.5" instead of the old 1.4 way "-source 1.3".

All well and good but 1.5 doesn't appear to let me compile with
"-source 1.3" to have an identifier named "assert". Apparently you
could do this with 1.4. If I try to 1.5 compile with "-source 1.3"
it returns the error that "assert is a keyword, try compiling
with -source 1.4, blah blah".

Does anybody know if this is correct and why they removed the
ability to compile as 1.3?

I get only a warning with 1.5.0_09:

~/java/java5> /usr/local/java/jdk1.5.0_09/bin/javac -source 1.3
NoAssert.java
NoAssert.java:5: warning: as of release 1.4, 'assert' is a keyword, and
may not be used as an identifier
(try -source 1.4 or higher to use 'assert' as a keyword)
int assert = 9;
^
1 warning
 
P

Phi

Hemal said:
I get only a warning with 1.5.0_09:

~/java/java5> /usr/local/java/jdk1.5.0_09/bin/javac -source 1.3
NoAssert.java
NoAssert.java:5: warning: as of release 1.4, 'assert' is a keyword, and
may not be used as an identifier
(try -source 1.4 or higher to use 'assert' as a keyword)
int assert = 9;
^
1 warning

I get warings and errors for the following class:

class Test {int assert;}

Comiling with javac -version 1.6.0
leads to "invalid source release", when I use [-source 1.0, 1.1 and
earlier ;-)]
leads to "compiler warnings", when I use [-source 1.2 and 1.3]
leads to "compiler errors", when I use [-source 1.4, 1.5 and 1.6]

By the way: For the java certification, have a look at the new
"Mock-Exam" I wrote for my students:
http://www.santis.ch/training/java/jcp/selftester/

Greetings and good luck for the Java Certification exam

phi
 
J

jupiter

Hemal Pandya said:
I get only a warning with 1.5.0_09:

I get it: I was trying to use identifer=assert plus assert
keywords. No can do; can do one but not both.

So, "javac -source 1.3 AssertIdentifier.java" with an "assert"
identifier will compile with only a warning. That is correct and
expected, I believe. That is the same as (purportedly) 1.4.

Good, that makes me feel better. The world is a good and stable
place again.

Thanks, Hemal.
 
J

jupiter

Phi said:
Hemal said:
I get only a warning with 1.5.0_09:

~/java/java5> /usr/local/java/jdk1.5.0_09/bin/javac -source 1.3
NoAssert.java
NoAssert.java:5: warning: as of release 1.4, 'assert' is a
keyword, and
may not be used as an identifier
(try -source 1.4 or higher to use 'assert' as a keyword)
int assert = 9;
^
1 warning

I get warings and errors for the following class:

class Test {int assert;}

Comiling with javac -version 1.6.0
leads to "invalid source release", when I use [-source 1.0, 1.1
and
earlier ;-)]
leads to "compiler warnings", when I use [-source 1.2 and 1.3]
leads to "compiler errors", when I use [-source 1.4, 1.5 and 1.6]

Hi, Phi, and I think that is all correct behavior. With -source
1.4 you cannot use "assert" as an identifer.

The problem I was creating was tyring to use an assert identifier
*plus* assert keywords in the same class. One or the other, with
the correct command line, is OK, but not both together.

Makes sense. My faux pas.



By the way: For the java certification, have a look at the new
"Mock-Exam" I wrote for my students:
http://www.santis.ch/training/java/jcp/selftester/

Greetings and good luck for the Java Certification exam

phi

Very cool! I'll be checking this out over the weekend. What gave
you the inspiration to do the work?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top