Access to a java member variable that has the name "type",

I am using the java library in which the 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 in order. But if I try to access it from scala:

 val x = new MyClass() x.type = 10 

I get this message:

Identifier

but the "type" is found.

How do I solve this problem?

I suppose this happened earlier, but I could not find a related question.

+4
source share
1 answer

You can do this in scala using backlinks:

 x.`type` = 10 

Any string enclosed in backticks can be used as an identifier or to access it.

+7
source

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


All Articles