我编写了一程序
如下:
public class M
{
public static void main(String[] args)
{
int k = 10; switch (10)
{
case 1:
System.out.println(1);
case 2:
System.out.println(2);
default:
//System.out.println("你好");
assert true: "出现了非预期错误!";
}
System.out.println("啦啦啦啦啦!");
}
}请问我在dos下输入什么命令可以编译M.java   启动断言   并运行本程序呢,
为什么我老启动不起来断言,我运行如下:
----------------------------------------------------------------------
C:\Documents and Settings\hb\桌面\java>java M
啦啦啦啦啦!C:\Documents and Settings\hb\桌面\java>java -ea M
啦啦啦啦啦!C:\Documents and Settings\hb\桌面\java>java M -ea
啦啦啦啦啦!
-----------------------------------------------------------------------

解决方案 »

  1.   

    对了 assert true: "出现了非预期错误!";  应该改为 assert false: "出现了非预期错误!"
    但是运行时还不对
      

  2.   

    java -ea
    不对!
    我运行如下:
    C:\Documents and Settings\hb\桌面\java>java -ea
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java [-options] -jar jarfile [args...]
               (to execute a jar file)where options include:
        -client       to select the "client" VM
        -server       to select the "server" VM
        -hotspot      is a synonym for the "client" VM  [deprecated]
                      The default VM is client.    -cp <class search path of directories and zip/jar files>
        -classpath <class search path of directories and zip/jar files>
                      A ; separated list of directories, JAR archives,
                      and ZIP archives to search for class files.
        -D<name>=<value>
                      set a system property
        -verbose[:class|gc|jni]
                      enable verbose output
        -version      print product version and exit
        -version:<value>
                      require the specified version to run
        -showversion  print product version and continue
        -jre-restrict-search | -jre-no-restrict-search
                      include/exclude user private JREs in the version search
        -? -help      print this help message
        -X            print help on non-standard options
        -ea[:<packagename>...|:<classname>]
        -enableassertions[:<packagename>...|:<classname>]
                      enable assertions
        -da[:<packagename>...|:<classname>]
        -disableassertions[:<packagename>...|:<classname>]
                      disable assertions
        -esa | -enablesystemassertions
                      enable system assertions
        -dsa | -disablesystemassertions
                      disable system assertions
        -agentlib:<libname>[=<options>]
                      load native agent library <libname>, e.g. -agentlib:hprof
                        see also, -agentlib:jdwp=help and -agentlib:hprof=help
        -agentpath:<pathname>[=<options>]
                      load native agent library by full pathname
        -javaagent:<jarpath>[=<options>]
                      load Java programming language agent, see java.lang.instrument    -splash:<imagepath>
                      show splash screen with specified imageC:\Documents and Settings\hb\桌面\java>java M
    啦啦啦啦啦!
      

  3.   

    preference-->java-->compiler,在JDK Compliance中打开assert选项
      

  4.   

    真晕
    java -ea M
    你自己的类名总要写上吧
      

  5.   

    汗!
    我把 assert false: "出现了非预期错误!" ;
    这行代码理解错啦!