alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (tailrec-2.scala)

This example Scala source code file (tailrec-2.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

a, a, bop, bop1, bop2, bop3, bop4, bop4, list, list, other, super, super

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

 

new blog posts

 

Copyright 1998-2021 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.