Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point[T : Numeric](val x:T, val y:T) {
- override def toString = "Numeric(" + x + ", " + y + ")"
- def + (other : Point[T]) : Point[T] = new Point[T] ( plus(this.x, other.x), plus(this.y, other.y))
- def - (other : Point[T]) : Point[T] = new Point[T] ( minus(this.x, other.x), minus(this.y, other.y))
- def unary_- : Point[T] = new Point[T](negate(this.x), negate(this.y))
- def == (other : Point[T]) : Boolean = (this.x == other.x && this.y == other.y)
- def != (other : Point[T]) : Boolean = !(this == other)
- private val numeric = implicitly[Numeric[T]]
- private def plus(x: T, y: T) = numeric.plus (x, y)
- private def minus(x: T, y: T) = numeric.minus (x, y)
- private def negate(x: T) = numeric.negate (x)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement