Sign in to follow this  

[java] assert errors

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently inherited a large amount of Java code from another developer, and he has used asserts in several of his files. All of those files have errors. Specifically, "Syntax error on token "assert", assert expected". This is within Eclipse, and pops up when I hover over the 'assert' keyword. I'm not terribly great with Java, and this is the first time I've encountered asserts. The syntax looks good [assert false; was the most simple one I found]. I'm using the 1.4.2 version of the SDK, and its worked fine for other projects I've done. Is there something I have to set up to get it to recognize asserts, or is there just something wrong with the code? Any help would be greatly appreciated. I'm not getting particuarly useful results through Google or the forum search, so this is my last resort. If this fails, I comment out all the asserts and move on. CM

Share this post


Link to post
Share on other sites
Quote:
Original post by retard
Dunno if you checked it out already, but you might want to check out Sun's page on using asserts in Java... it's rather helpful.

http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Thanks for the link, but I had already read it. That's why I'm pretty sure the syntax is correct. There was the section about whether or not assert is allowed as a variable name, but I'm not sure how that could be my problem.

CM

Share this post


Link to post
Share on other sites
Sounds like a compiler setup problem.
Quote:
from http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Compiling Files That Use Assertions
In order for the javac compiler to accept code containing assertions, you must use the -source 1.4 command-line option as in this example:

javac -source 1.4 MyClass.java
This flag is necessary so as not to cause source compatibility problems.

Share this post


Link to post
Share on other sites
Quote:
Original post by lucinpub
Sounds like a compiler setup problem.
Quote:
from http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html

Compiling Files That Use Assertions
In order for the javac compiler to accept code containing assertions, you must use the -source 1.4 command-line option as in this example:

javac -source 1.4 MyClass.java
This flag is necessary so as not to cause source compatibility problems.

Bah...you're right, I'm a complete idiot. I read that several times, and each time I left with the conclusion that -source 1.3 allowed asserts. Bleh.

That fixed it right up. I suppose this means I have no choice but to get back to work. Damn it. [grin]

Thanks a million.

CM

Share this post


Link to post
Share on other sites

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this