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
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With