|
Scala example source code file (null-and-intersect.scala)
The Scala null-and-intersect.scala source code
object Test {
trait Immortal
class Bippy extends Immutable with Immortal
class Boppy extends Immutable
def f[T](x: Traversable[T]) = x match {
case _: Map[_, _] => 3
case _: Seq[_] => 2
case _: Iterable[_] => 1
case _ => 4
}
def g(x: Bippy) = x match {
case _: Immutable with Immortal => 1
case _ => 2
}
def h(x: Immutable) = x match {
case _: Immortal => 1
case _ => 2
}
def main(args: Array[String]): Unit = {
println(f(Set(1)))
println(f(Seq(1)))
println(f(Map(1 -> 2)))
println(f(null))
println(g(new Bippy))
println(g(null))
println(h(new Bippy))
println(h(new Boppy))
println(h(null))
}
}
Other Scala examples (source code examples)Here is a short list of links related to this Scala null-and-intersect.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.