enguerran
enguerran

Reputation: 3291

Scala in java code : $colon

I read some java source code which including Scala source code.

I found Nil.$colon$colon(Object arg)

What does keywords $colon mean? And what does this line mean?

Upvotes: 4

Views: 1014

Answers (1)

David Pierre
David Pierre

Reputation: 9545

$colon is a mangling for the symbol :. Since : (and other letters) is an illegal letter in java for method names but allowed in scala, a strategy is needed to encode it into a legal name. Hence, the $colon

Here your code translate to arg :: Nil which adds arg to the empty list, constructing a List with arg as single element.

Upvotes: 14

Related Questions