Can't figure out what's wrong with StrangeIntQueue extending Queue, why there is an error "Not enough arguments for constructor Queue: (leading: Int)list.Lister.Queue[Int]. Unspecified value parameter leading". How can I specify it?
class Queue[+T](
private val leading: T
) {
def enqueue[U >: T](x: U) =
new Queue[U](leading: U) // ...
}
class StrangeIntQueue(private val leading: Int) extends Queue[Int] {
override def enqueue(x: Int) = {
println(math.sqrt(x))
super.enqueue(x)
}
}
If the brackets don't all match up, the result is a compile time error. The fix to this compile error is to add a leading round bracket after the println to make the error go away: int x = 10; System.
As shown, scalacOptions lets you set Scala compiler options in your SBT project build. I got that example from my earlier very large Scala/SBT build. sbt example. Also, I just saw that tpolecat has put together a nice list of scalaOptions flags at this URL.
extends Queue[Int](leading)
You have to pass on the arguments even if it seems "obvious" what to do.
Note also that since you have declared leading
private, you'll actually get two copies: one for StrangeIntQueue
and one for Queue
. (Otherwise you could have just StrangeIntQueue(leading0: Int) extends Queue[Int](leading0)
and use the inherited copy of leading
inside.)
The primary constructor of class Queue
, which StrangeIntQueue
extends, takes a parameter, but you're not passing it anything for the parameter. Try this:
class StrangeIntQueue(leading: Int) extends Queue[Int](leading) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With