Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot get code with assertions to compile

 
Chiran Mathur
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 366
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic