Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 809
enguerran Avatar asked Dec 10 '22 19:12

enguerran


1 Answers

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

like image 190
David Pierre Avatar answered Dec 24 '22 10:12

David Pierre