Cannot set a java annotation member called type in scala?

java, scala, scala-java-interop

Solution

You can use backticks 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

Problem

I am trying to port some java code to scala. The code uses annotations with a member called `type` however this is a keyword in scala. Is there a 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 escape the `type` keyword? This is also a problem with java classes with a `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 } ```

Original source