What is the meaning of the colon, underscore, and star in a SiteMap listing (entries: _ *)?

I am learning Scala and lift at the same time, and I am stuck in understanding the syntax used to initialize SiteMap in Boot.scala:

val entries = Menu(Loc("Home", "/", "Home")) :: Menu(Loc("Foo", "/badger", "Foo")) :: Menu(Loc("Directory Foo", "/something/foo", "Directory Foo")) :: Nil LiftRules.setSiteMap(SiteMap(entries:_*)) 

What exactly does the SiteMap parameter mean? I see that the values ​​are a list of menus. What is a colon, underscore, star ? At first I thought it was a method on the List, but I could not find such a definition ...

+56
scala lift
Jul 14 '09 at 8:06
source share
1 answer

Well, after my colleague told me that he had encountered this secret spell in Programming in Scala , I did a search in my copy and found it in Section 8.8 Duplicate Parameters. (Although you need to look for a space between the colon and the underscore: - /) There is one sentence that explains this as:

... add an array argument with a colon and the symbol _* , for example: scala> echo(arr: _*)

This notation tells the compiler to pass each arr element as its own echo argument, and not all of it as one argument.

I find here the description offered here .

So x: _* like a type declaration that tells the compiler to treat x as a repeating parameter (also known as a list of arguments of variable length vararg ).

+71
Jul 14 '09 at 8:31
source share



All Articles