File: null-and-intersect.scala

package info (click to toggle)
scala 2.11.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,828 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,250; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (34 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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))
  }
}