472,805 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*n¯à©Ó¾á*·ÀI ~

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

-- Let us OpenSource --
Jul 18 '05 #1
3 12151
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
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*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
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*n¯à©Ó¾á*·ÀI ~

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

-- Let us OpenSource --

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Doe | last post by:
Hello, I'm currently working on a little tool that would benefit from having a little embedded script language. Although I have C++ source code available for such a script language, I have 2...
28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
1
by: Zean Smith | last post by:
I am working on a project to migrate a JavaBean + JSP application (running on Oracle application server) to Microsoft ASP.NET + SQL server. In order to see how the original code works, I need to...
0
by: Nick | last post by:
Hi, I'm facing certain issues while trying to compile a java class using the Visual J# compiler into a dot net readable DLL. However, I'm getting stuck at a point where there is a reference to a...
1
by: marco_segurini | last post by:
Hi, Is there any way in C# to perform a compile-time-assert (like BOOST_STATIC_ASSERT in C++)? Thanks a lot. Marco.
1
by: kaushikm | last post by:
How to access sql server inbuilt functions from java prepared statement ? I have used getdate() of sql in a java prepared statement and am connecting to sqlserver. But it's not working. What to do ?
11
by: Francois Grieu | last post by:
Hi, I'm using an assert()-like macro to test a constant expression at compile time #define ASSERT(condition) struct{char assert_failure;} The idea is that this macro cause a compilation...
4
by: robtyketto | last post by:
Greetings, I've got my head spinning with some very simple java coding, Im a newbie to Java and utilising the code below for a javabean for some jsp Im working on. The problem is my code I've...
2
by: bob2044 | last post by:
Ive just started using java . Ive a problem to compile java using cmd.need a help!
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.