Scala in java code: $ colon

I read some java source code that includes Scala source code.

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

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

+4
source share
1 answer

The $ colon is the character for the character :. Since: (and other letters) is an illegal letter in java for method names, but is allowed in scala, to encode it, you must enter the strategy in the legal name. Therefore, $ colon

Here, your code translates to arg :: Nil, which adds arg to an empty list, creating a List with arg as a separate item.

+14
source

All Articles