java中星号下划线代表啥意思,在Lift的SiteMap中,冒号,下划线和星号是什么意思(条目:_ *)?...

I'm learning Scala and lift at the same time and I got stuck on understanding the syntax used to inintialize the SiteMap in the 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 is the meaning of the SiteMap parameter?

I see that the value entries is a list of Menu. What is the colon, underscore, star?

At first I thought it is a method on the List, but I am unable to find such definition...

解决方案

OK, after my colleague mentioned to me, that he encountered this secret incantation in the Programming in Scala book, I did a search in my copy and found it described in Section 8.8 Repeated parameters. (Though you need to search with space between the colon and underscore :-/ ) There is a one sentence to explain it as:

... append the array argument with a colon and an _* symbol, like this:

scala> echo(arr: _*)

This notation tells the compiler to pass each element of arr as its own argument to echo, rather than all of it as a single argument.

So x: _* is like a type declaration that tells the compiler to treat x as repeated parameter (aka variable-length argument list — vararg).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值