Why is this code not compiled in javac, but there are no errors in eclipse?
•
Java
The following codes:
@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 {}; }
Compiled in eclipse but not in sun / Oracle compiler:
> MinTimeValueCo.java:19: illegal start of expression > [javac] }) > [javac] ^ > [javac] 1 error
This is because mintimedoublecolistconstraintvalidator Comma after class
It works when I delete commas:
@Constraint(validatedBy = { MinTimeIntCoConstraintValidator.class,MinTimeDoubleCoListConstraintValidator.class })
I use JDK 1.6 0.10. Do you know why this is illegal and compiled in eclipse?
Solution
This is an error in javac of Java 6 There are 07000 in some places, the eclipse compiler follows the standard here, and Java 6 never allows trailing commas anywhere
You can try to compile the code using javac in Java 7 with the option - source 6 - target 6 (to get Java 6 compatible bytecode) If the error persists, file it It may be repaired
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码