加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

为什么这段代码没有用javac编译但在eclipse中没有错误?

发布时间:2020-12-14 05:39:08 所属栏目:Java 来源:网络整理
导读:以下代码: @Retention(RetentionPolicy.RUNTIME)@Target( { ElementType.METHOD,ElementType.FIELD,ElementType.ANNOTATION_TYPE })@Constraint(validatedBy = { MinTimeIntCoConstraintValidator.class,MinTimeIntCoListConstraintValidator.class,MinTime
以下代码:
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.METHOD,ElementType.FIELD,ElementType.ANNOTATION_TYPE })
@Constraint(validatedBy = {
        MinTimeIntCoConstraintValidator.class,MinTimeIntCoListConstraintValidator.class,MinTimeDoubleCoConstraintValidator.class,MinTimeDoubleCoListConstraintValidator.class,})
@Documented
public @interface MinTimeValueCo
{
    int value();
    String message() default "value does not match minimum requirements";
    Class<?>[] groups() default { };
    Class<? extends Payload>[] payload() default {};
}

在eclipse中编译但无法在sun / oracle编译器中编译:

> MinTimeValueCo.java:19: illegal start of expression
>     [javac]       })
>     [javac]       ^
>     [javac] 1 error

这是因为MinTimeDoubleCoListConstraintValidator.class之后的逗号.

当我删除逗号时它工作正常:

@Constraint(validatedBy = {
        MinTimeIntCoConstraintValidator.class,MinTimeDoubleCoListConstraintValidator.class
        })

我使用的是jdk 1.6.0.10.
你知道为什么这是非法的并且在eclipse中编译吗?

解决方法

这是Java 6的javac中的一个错误.在某些地方有07??000,Eclipse编译器遵循这里的标准,而Java 6从不允许在任何地方使用尾随逗号.

您可以尝试使用Java 7中的javac使用选项-source 6 -target 6编译代码(以获取Java 6兼容的字节代码).如果错误仍然存??在,file it.它可能会得到修复.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读