简体   繁体   English

什么是List [String~Int]?

[英]What is List[String~Int]?

While going through the scala documentation ( Play Docs ) of the play framework I saw a syntax I have never seen before. 在浏览play框架的scala文档( Play Docs )时,我看到了一种我从未见过的语法。

val populations:List[String~Int] = {
  SQL("select * from Country").as( str("name") ~ int("population") * ) 
}

Could someone please tell me what does "~" in List[String~Int] mean? 请问有人请告诉我List[String~Int]中的“〜”是什么意思?

May be this willl help: 可能是这个帮助:

scala> class ~[A, B]
defined class $tilde

scala> List.empty[String~Int]
res1: List[~[String,Int]] = List()

Actually, ~ is not a part of the standard library, this is a generic class from the play framework, which allows an infix notation. 实际上, ~不是标准库的一部分,这是一个来自play框架的泛型类,它允许使用中缀表示法。 In scala, any generic class that takes 2 generic parameters can be use with an infix notation. 在scala中,任何带有2个泛型参数的泛型类都可以使用中缀表示法。 for example, the following also works: 例如,以下也有效:

scala> class X[A, B]
defined class X

scala> List.empty[String X Int]
res1: List[X[String,Int]] = List()

In your case, you will find the definition of ~ in the Play framework API . 在您的情况下,您将在Play框架API中找到~的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM