An array of annotations as an annotation parameter in Scala

There are many questions about passing an array as a parameter to the annotation; this is not a hoax.

I would like to use Java-land annotation, which takes an array of annotations as a parameter, for example.

@ManagedOperation @ManagedOperationParameters({ @ManagedOperationParameter(name="start"), @ManagedOperationParameter(name="end") }) def stuff(start: String, end: String): Unit = ??? 

But this is not valid syntax in Scala, not

 @ManagedOperation @ManagedOperationParameters(Array( @ManagedOperationParameter(name="start"), @ManagedOperationParameter(name="end") )) def stuff(start: String, end: String): Unit = ??? 

so is this the right way to do it if possible?

By the way, I even checked all github to see if any Scala devs use this annotation (Spring JMX).

+8
spring scala annotations
source share
1 answer

In scala, the internal annotation should be used as a regular type:

 @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "moduleType", defaultImpl = classOf[PuppetModule] ) @JsonSubTypes(Array( new Type(value = classOf[PuppetModule], name = "puppet"), new Type(value = classOf[PluginModule], name = "plugin") )) trait Module { val moduleType: String = if (this.isInstanceOf[PuppetModule]) "puppet" else "plugin" val nodes: List[String] = List[String]() } 
+4
source share

All Articles