469,352 Members | 1,982 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

how to compile java with assert statement

how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ 股票價格有升有跌, 買賣*n能承擔*滅I ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
Jul 18 '05 #1
3 11908
SOAP wrote:
how to compile java with assert statement


Read the documentation that came with the JVM, specifically on the javac
tool.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2
Most of current IDE tools have the option: "allow assert keyword"

By default it is usually off, and you can turn it on.

If you use javac, you can use the switch in the command line that enables
assertions.

javac -enableassertions YourFile.java
or
javac -ea YourFile.java

--
Jeff Zhuk

720-299-4701
http://JavaSchool.com
jz***@email.uophx.edu
alternative: jz***@javaschool.com
ITS, Inc., Chief Architect/Principal Instructor

"SOAP" <s@soap.com> wrote in message news:42******@usenet.hk...
how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not
be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ 股票價格有升有跌, 買賣*n能承擔*滅I ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --

Jul 18 '05 #3
You also need to enable runtime assertions with the switch

java -ea:your.package YourClass

Find more at
http://java.sun.com/j2se/1.4.2/docs/...html#compiling

--
Jeff Zhuk

720-299-4701
http://JavaSchool.com
jz***@email.uophx.edu
alternative: jz***@javaschool.com
ITS, Inc., Chief Architect/Principal Instructor

"SOAP" <s@soap.com> wrote in message news:42******@usenet.hk...
how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not
be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ 股票價格有升有跌, 買賣*n能承擔*滅I ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John Doe | last post: by
28 posts views Thread by F墎io Mendes | last post: by
1 post views Thread by Zean Smith | last post: by
1 post views Thread by marco_segurini | last post: by
11 posts views Thread by Francois Grieu | last post: by
2 posts views Thread by bob2044 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.