j**a 断言

时间:2013.10.12 发布人:ylx8000

j**a 断言

已解决问题

谷歌ylx8000用户在2013.10.12提交了关于“威海j**a 断言”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-08-24T15:06:45。classTest
{
voidprocess(intage)
{
assertage<=0:"年龄有误";
System.out.println(age);
}
publicstaticvoidmain(String[]args)
{
newTest().process(-5);
}
}
在编译的时候j**ac***.j**a会出现
C:\>j**ac***.j**a
***.j**a:5:warning:asofrelease1.4,assertisakeyword,andmaynotbeuse
dasanidentifier
assertage<=0:"年龄有误";
^
***.j**a:5:';'expected
assertage<=0:"年龄有误";
^
1error
1warning
错误

为什么?谢谢希望大家能够帮助她。

详细问题描述及疑问:classTest
{
voidprocess(intage)
{
assertage<=0:"年龄有误";
System.out.println(age);
}
publicstaticvoidmain(String[]args)
{
newTest().process(-5);
}
}
在编译的时候j**ac***.j**a会出现
C:\>j**ac***.j**a
***.j**a:5:warning:asofrelease1.4,assertisakeyword,andmaynotbeuse
dasanidentifier
assertage<=0:"年龄有误";
^
***.j**a:5:';'expected
assertage<=0:"年龄有误";
^
1error
1warning
错误

为什么?谢谢期待您的答案,千言万语,表达不了我的感激之情,我已铭记在心 !

希望以下的回答,能够帮助你。

第1个回答

用户名:huske394来自392  

由于assert问答是一个新关键字,使用老版本的JDK是无法编译带有assert的源程序。因此,我们必须使用JDK1.4(或者更新)的J**a编译器,在使用Javac命令时,我们必须加上-source1.4作为参数。-source1.4表示使用JDK1.4版本的方式来编译源代码,否则编准气输妒的色代你矛译就不能通过,因为缺省的J**ac编译器使用JDK1.3的语法规则。