java assertion compiling error

Discussion in 'Mac Programming' started by ScKaSx, Apr 9, 2007.

  1. macrumors regular

    Joined:
    Feb 27, 2006
    #1
    I am trying to compile an example for java from THE REALLY BIG INDEX:
    http://java.sun.com/docs/books/tutorial/java/javaOO/examples/Card.java

    However whenever I try to compile:
    javac Card.java
    I get the following error:
    "warning: as of release 1.4, assert is a keyword, and may not be used as an identifier"

    And if I try to compile it with enable assertions I get:
    javac: invalid flag: -ea
    Usage: javac <options> <source files>

    Any ideas on how to get this code to compile? I am running Java version 1.4.2_12, which I believe should be able to handle assertions. Thanks for your help.

    Cheers,
    ScKaSx
     
  2. macrumors 6502

    Joined:
    May 12, 2003
    #2
    Warning messages aren't fatal. If that's all you saw, then the compile was probably successful. Do you see a Card.class in that directory? If so, then you don't need to do anything about the warning.

    Also, while I didn't actually try this (nor have I ever used assertions in Java), it looks like you add the '-ea' flag when running your program, not when compiling it. Like this:
    Code:
    java -ea Card
    
    More info on assert here.
     
  3. macrumors 6502a

    Joined:
    Nov 10, 2006
    #3
    From memory, I think it's something like
    javac -source 1.4

    Then it will understand the asserts as being asserts and not a variable named assert.
     
  4. thread starter macrumors regular

    Joined:
    Feb 27, 2006
    #4
    Thanks -source 1.4 works!

    Hey Guys,

    Thanks for the response. What worked for me was aloc's suggestion to compile with the flag -source 1.4. Thanks again.

    Cheers,
    ScKaSx
     

Share This Page