在Lift的SiteMap中,冒号,下划线和星号是什么意思(条目:_ *)? [英] What is the meaning of colon, underscore and star in lift's SiteMap(entries:_*)?

查看:109
本文介绍了在Lift的SiteMap中,冒号,下划线和星号是什么意思(条目:_ *)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Scala lift 同时出现,我陷入了理解用于初始化 SiteMap 在Boot.scala中:

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:_*))

SiteMap参数的确切含义是什么? 我看到值 entries 是Menu的列表.什么是下划线,星号? 起初我以为这是List上的一种方法,但是我找不到这样的定义...

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:

...在数组参数后面附加冒号和 _* 符号,如下所示: scala> echo(arr: _*)

... append the array argument with a colon and an _* symbol, like this: scala> echo(arr: _*)

此符号告诉编译器将arr的每个元素作为其自己的参数传递给echo,而不是将所有元素作为一个参数传递.

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.

我找到了因此x: _*类似于 类型声明,告诉编译器将x视为重复参数(又名变长参数列表— vararg ).

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

这篇关于在Lift的SiteMap中,冒号,下划线和星号是什么意思(条目:_ *)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆