带有 CircularFifoQueue 的 scala 案例 class
scala case class with CircularFifoQueue
Scala 编译器针对以下
抛出编译错误
case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
以下错误消息来自 Scala REPL:
$scala -cp Downloads/commons-collections4-4.1.jar
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
scala> import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.apache.commons.collections4.queue.CircularFifoQueue
scala> case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
<console>:1: error: identifier expected but ')' found.
case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
^
scala> case class UserSession(userEvents: CircularFifoQueue<int>)
<console>:1: error: identifier expected but ')' found.
case class UserSession(userEvents: CircularFifoQueue<int>)
对 scala 中的泛型使用 []
而不是钻石 (<>
),这是 java 的事情。
应该是case class UserSession(userEvents: CircularFifoQueue[UserEvent])
简单的泛型示例,
scala> class Bag[T]
defined trait Bag
scala> case class Apple()
defined class Apple
scala> new Bag[Apple]()
res4: Bag[Apple] = Bag@1ef93e01
资源
Scala 编译器针对以下
抛出编译错误case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
以下错误消息来自 Scala REPL:
$scala -cp Downloads/commons-collections4-4.1.jar
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
scala> import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.apache.commons.collections4.queue.CircularFifoQueue
scala> case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
<console>:1: error: identifier expected but ')' found.
case class UserSession(userEvents: CircularFifoQueue<UserEvent>)
^
scala> case class UserSession(userEvents: CircularFifoQueue<int>)
<console>:1: error: identifier expected but ')' found.
case class UserSession(userEvents: CircularFifoQueue<int>)
对 scala 中的泛型使用 []
而不是钻石 (<>
),这是 java 的事情。
应该是case class UserSession(userEvents: CircularFifoQueue[UserEvent])
简单的泛型示例,
scala> class Bag[T]
defined trait Bag
scala> case class Apple()
defined class Apple
scala> new Bag[Apple]()
res4: Bag[Apple] = Bag@1ef93e01