Can't set a java annotation element called type in scala?

I am trying to port some java code to scala. The code uses annotations with a member named type , but this is a keyword in scala. Is there any way to address this valid java member in scala?

Here is the Java code

 @Component( name = "RestProcessorImpl", type = mediation // Compile error ) public class RestProcessorImpl { // impl } 

This part of the code is identical in scala, except that type is a keyword, so it does not compile. Is there a way to avoid the type keyword?

This is also a problem with java classes with type member

HasType.java

 package spike1; public class HasType { public String type() { return "the type"; } } 

UseType.scala

 class UseType { def hasType = new HasType hasType.type() // Compile error } 
+6
source share
1 answer

You can use backlinks to get around illegal identifiers:

 val type = 1 // error val `type` = 1 // fine 

So, with your code, you can do this:

 val hasType = new HasType hasType.`type`() // no error 
+15
source

Source: https://habr.com/ru/post/914642/


All Articles