Scala的类继承
Scala的类继承
}
class Person { override def toString = getClass.getName +"name=" } 在Scala中调用的超类的方法和java完全一致,使用super关键字 public class Employee extends Person { override def toString = super.toString }
if(p.isInstanceOf[Employee]) { // s的类型为Employee val s = p.asInstanceOf[Employee] }
父类: class Animal { val age : Int = 10 val array : Array[Int] = new Array[Int](age) } 子类: class Ant extends Animal { override val age = 2 } 类装载机制运行大致如下
1. 将val声明为final 2. 在超类中val声明为lazy 3. 在子类总使用提前定义语法如下: class Ant extends{ override val range = 2}with Animal
final override def equals(other: Any) = { val that = other.asInstanceOf[Item] if(that==null) false else description ==that.description && price ==that.price } 注意要确保equals的方法参数类型为Any,否则不会重写equals方法 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- typescript – 将Page / Global Variables传递到Angular2应
- scala – 命名参数会导致维护问题和低可读性?
- FTP协议的工作流程
- Scala val和var相关的问题和scala要求我在声明时分配一个值
- Jersey Restful WebService 接收 JSON 数组 对象
- scala – 为了细节而重新运行
- localStorage未定义(Angular Universal)
- Scala简介及基础语法
- twitter-bootstrap – 如何通过webpack 2从bootstrap 4中仅
- angularjs – Angular 1.3.14 merge(dst)不存在