why is this code not compiling with javac but has no errors in eclipse?

大兔子大兔子 提交于 2019-12-04 05:57:14

This is a bug in Java 6's javac. The JLS allows trailing commas in some places and the Eclipse compiler follows the standard here while Java 6 never allows trailing commas anywhere.

You can try to compile your code with javac from Java 7 with the options -source 6 -target 6 (to get Java 6 compatible byte code). If the bug is still there, file it. It might get fixed.

You have a , at the end of MinTimeDoubleCoListConstraintValidator.class, it is looking for another expression in the list.

It looks like you are declaring some sort of array of constraints. You are placing an extra comma (,) after your last constraint, thus making the compiler expect some other value together with the ones you already have. Try doing this:

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

By having a comma after MinTimeDoubleCoListConstraintValidator.class, the java compiler thinks there should be another value. Eclipse accepts the trailing comma, but javac does not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!