I am using a java library in which a class has a member named "type". If I do something like this:
class MyClass{
public MyClass(){
type = 5;
}
public int type;
}
then the java compiler compiles it fine. But if I try to access it from scala:
val x = new MyClass()
x.type = 10
I get this message:
identifier expected but 'type' found.
How do I work around this issue?
I am guessing this has come up before but I could not find a related question.
You can do this in scala by using backticks:
x.`type` = 10
Any string enclosed in backticks can be used as an identifier, or to access one.
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