java assertion compiling error

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

  1. ScKaSx macrumors regular

    Feb 27, 2006
    I am trying to compile an example for java from THE REALLY BIG INDEX:

    However whenever I try to compile:
    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.

  2. therevolution macrumors 6502

    May 12, 2003
    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:
    java -ea Card
    More info on assert here.
  3. aLoC macrumors 6502a

    Nov 10, 2006
    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. ScKaSx thread starter macrumors regular

    Feb 27, 2006
    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.


Share This Page