|
Scala example source code file (tailrec-2.scala)
The Scala tailrec-2.scala source code
sealed abstract class Super[+A] {
def f[B >: A](mem: List[B]) : List[B]
}
// This one should fail, target is a supertype
class Bop1[+A](val element: A) extends Super[A] {
@annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Super[A]).f(mem)
}
// These succeed
class Bop2[+A](val element: A) extends Super[A] {
@annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Bop2[A]).f(mem)
}
object Bop3 extends Super[Nothing] {
@annotation.tailrec final def f[B](mem: List[B]): List[B] = (null: Bop3.type).f(mem)
}
class Bop4[+A](val element: A) extends Super[A] {
@annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = Other.f[A].f(mem)
}
object Other {
def f[T] : Bop4[T] = sys.error("")
}
object Bop {
def m1[A] : Super[A] = sys.error("")
def m2[A] : Bop2[A] = sys.error("")
}
Other Scala examples (source code examples)Here is a short list of links related to this Scala tailrec-2.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.