views:

228

answers:

1

Hi,

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?

+12  A: 

$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.

David Pierre
Since I understand your answer, I would like to ask: What does 'mangling' mean exactly?
enguerran
It basically means having a different identifier used for the runtime than is present in the source code.See http://en.wikipedia.org/wiki/Name_mangling .
David Winslow