summaryrefslogtreecommitdiff
path: root/test/files/run/Meter.scala
blob: 5700025880f4f6b865bf9f2485762d8b80567fad (plain) (blame)
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
35
36
37
38
class Meter(val underlying: Double) extends AnyVal with Printable {
   def + (other: Meter): Meter = 
     new Meter(this.underlying + other.underlying)
   def / (other: Meter): Double = this.underlying / other.underlying
   def / (factor: Double): Meter = new Meter(this.underlying / factor)
   def < (other: Meter): Boolean = this.underlying < other.underlying
   override def toString: String = underlying.toString+"m"
}
trait Printable extends Any { def print: Unit = Console.print(this) }

object Test extends App {

  {
  val x: Meter = new Meter(1)
  val a: Object = x.asInstanceOf[Object]
  val y: Meter = a.asInstanceOf[Meter]

  val u: Double = 1
  val b: Object = u.asInstanceOf[Object]
  val v: Double = b.asInstanceOf[Double]
  }

  val x = new Meter(1)
  val y = x
  println((x + x) / x)
  println((x + x) / 0.5)
  println((x < x).toString)


  println("x.hashCode: "+x.hashCode)
  println("x == 1: "+(x == 1))
  println("x == y: "+(x == y))
  assert(x.hashCode == (1.0).hashCode)
  
  val a: Any = x
  val b: Any = y
  println("a == b: "+(a == b))
}