Skip to content

Support Java 8 repeating annotations #9529

@scabug

Description

@scabug

Repeating annotations: [https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html]

Java couldn't deal with it with in a straight-forward fashion, because Java, so we should have a look whether we can clean up this mess and make users code work.

As reported in gitter.im/scala/scala by user hepin1989:

Caused by: java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface qgame.engine.component.module.ModuleConfigPath: @qgame.engine.component.module.ModuleConfigPath(path=sample-module)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:125)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.Class.createAnnotationData(Class.java:3521)
    at java.lang.Class.annotationData(Class.java:3510)
    at java.lang.Class.getDeclaredAnnotationsByType(Class.java:3469)
    at qgame.engine.component.module.ModuleRunner.<init>(ModuleRunner.scala:31)

I have had

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Repeatable(ServiceDependencies.class)
@Inherited
public @interface ServiceDependency {}

and

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface ServiceDependencies {
    ServiceDependency[] value();
}

and retrieve it with

getDeclaredAnnotationsByType(classOf[ServiceDependency])

have to use it like the old way:

@ServiceDependencies(Array(
  new ServiceDependency(name = "ping", maxRecheckTimes = 10, reCheckInterValInSeconds = 5),
  new ServiceDependency(name = "pong", maxRecheckTimes = 10, reCheckInterValInSeconds = 5)
))

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions