Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: "val" as identifier possible? Linking to java library needs it [duplicate]

In my scala code, I'm using a java library which defines an object with a public attribute called "val":

public class XYZ {
    public int val=...
}

Is there a way to get this attribute in scala?

like image 960
Heinzi Avatar asked Mar 21 '13 12:03

Heinzi


1 Answers

You can use backticks. They remove the reserved status of any Scala keyword (or symbol).

val foo = new XYZ
foo.`val`

See the Scala Interoperability FAQ.

like image 151
ach Avatar answered Oct 18 '22 04:10

ach