It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Cannot get code with assertions to compile Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Cannot get code with assertions to compile" Watch "Cannot get code with assertions to compile" New topic
Author

Cannot get code with assertions to compile

Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
Do I need to import any particular package for assertions to work. I am using JBuilder 7 and it is uisng JDk1.4.0 and it just doesn't recognize the word assert.
Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
package assertUse;
import java.util.*;
import java.io.*;
import java.lang.Error.*;
public class AssertTest{
public void methodA(int i) throws AssertionError{
assert i < 1024 : "Invalid Value";
}
}
I always get this error while compilingthe above code:
"assertUse.java": Error #: 200 : ';' expected at line 7, column 18
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
Chiran,
one possible problem might be the way you are compiling the code.
In order for the code with assertions to be compiled, you have to type
javac -source 1.4 AssertTest.java
I tried the same code and it compiles just fine
Hope this helps
Sri
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Cannot get code with assertions to compile
 
Similar Threads
Exam for JDK1.4
Pointers
assertion code overhead when disabled
What does the java runtime option -cs do?
assertions