首页 > 其他 > 详细

trait1

时间:2018-07-07 21:56:49      阅读:184      评论:0      收藏:0      [点我收藏+]
package com.bjsxt.scala

trait IsEQU{
  def isEqu(o:Any):Boolean
  def isNotEqu(o:Any) :Boolean = !isEqu(o)
}

class Point(xx:Int, xy:Int) extends IsEQU {
  val x = xx
  val y = xy

  def isEqu(o: Any): Boolean = {
     o.isInstanceOf[Point]&&o.asInstanceOf[Point].x == this.x
  }
}

object Lesson_Trait2 {
  def main(args: Array[String]): Unit = {
    val point1 = new Point(1,2)
		val point2 = new Point(1,3)
    println(point1.isNotEqu(point2))
  }
}

  

trait1

原文:https://www.cnblogs.com/huiandong/p/9278276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!