每个次构造函数需要委托给主构造函数, 可以直接委托或者通过别的次构造函数间接委托。委托到同一个类的另一个构造函数用 this 关键字即可

class Person {
  constructor(parent: Person) {
    parent.children.add(this)
  }
}

class Person(val name: String) {
constructor(name: String, parent: Person) : this(name) {
parent.children.add(this)
}
}

kotlin class 默认是final 不能继承

非要继承必须声明成open

abstract  默认是open的。

final 不能被覆写 在kotlin中默认所有的方法和类都是final属性
open 可以被覆写 需要被明确指出
abstract 必须要覆写 不能被实例化,默认具有open属性。
override 覆写超类的方法 如果没有被指定为final,则默认具有open属性

如果派生类有一个主构造函数,其基类型可以(并且必须) 用基类的主构造函数参数就地初始化。

kotlin class的更多相关文章

  1. Kotlin的Lambda表达式以及它们怎样简化Android开发(KAD 07)

    作者:Antonio Leiva 时间:Jan 5, 2017 原文链接:https://antonioleiva.com/lambdas-kotlin/ 由于Lambda表达式允许更简单的方式建模式 ...

  2. 用Kotlin实现Android定制视图(KAD 06)

    作者:Antonio Leiva 时间:Dec 27, 2016 原文链接:https://antonioleiva.com/custom-views-android-kotlin/ 在我们阅读有关c ...

  3. Kotlin与Android SDK 集成(KAD 05)

    作者:Antonio Leiva 时间:Dec 19, 2016 原文链接:https://antonioleiva.com/kotlin-integrations-android-sdk/ 使用Ko ...

  4. Kotlin的android扩展:对findViewById说再见(KAD 04)

    作者:Antonio Leiva 时间:Dec 12, 2016 原文链接:http://antonioleiva.com/kotlin-android-extensions/ 你也许已厌倦日复一日使 ...

  5. Kotlin类:功能更强、而更简洁(KAD 03)

    作者:Antonio Leiva 时间:Dec 7, 2016 原文链接:http://antonioleiva.com/classes-kotlin/ Kotlin类尽可能简单,这样用较少的代码完成 ...

  6. Kotlin中变量不同于Java: var 对val(KAD 02)

    原文标题:Variables in Kotlin, differences with Java. var vs val (KAD 02) 作者:Antonio Leiva 时间:Nov 28, 201 ...

  7. 用Kotlin创建第一个Android项目(KAD 01)

    原文标题:Create your first Android project using Kotlin (KAD 01) 作者:Antonio Leiva 时间:Nov 21, 2016 原文链接:h ...

  8. Android的Kotlin秘方(II):RecyclerView 和 DiffUtil

    作者:Antonio Leiva 时间:Sep 12, 2016 原文链接:http://antonioleiva.com/recyclerview-diffutil-kotlin/ 如你所知,在[支 ...

  9. Android的Kotlin秘方(I):OnGlobalLayoutListener

    春节后,又重新“开张”.各位高手请继续支持.谢谢! 原文标题:Kotlin recipes for Android (I): OnGlobalLayoutListener 原文链接:http://an ...

  10. KOTLIN开发语言文档(官方文档) -- 2.基本概念

    网页链接:https://kotlinlang.org/docs/reference/basic-types.html 2.   基本概念 2.1.  基本类型 从可以在任何变量处理调用成员函数和属性 ...

随机推荐

  1. angular-file-upload.min.js.map文件下载

    https://github.com/nervgh/angular-file-upload 下载地址 在文件 菜单栏有对应文件

  2. js获取图片内容上传

    <script> $('#pic').change(function(){ var size=document.getElementById('pic').files[0].size va ...

  3. SpringBoot + Dubbo + zookeeper 搭建简单分布式服务

    SpringBoot + Dubbo + zookeeper 搭建简单分布式服务 详细操作及源码见: https://github.com/BillyYangOne/dubbo-springboot

  4. ES6 map与filter

    ES6 map与filter 1.map let arr1 = [1,2,3]; let arr2 = arr1.map((value,key,arr) => { console.log(val ...

  5. 深入SpringBoot注解原理及使用

    首先,先看SpringBoot的主配置类: @SpringBootApplication public class StartEurekaApplication { public static voi ...

  6. VUE【四、组件】

    今天周五了,这周由于开始了健身计划,晚上几乎没精力继续看书了,早上也很困..可能刚开始不适应,适应了就好了..只能挤挤时间抓紧看 原计划这周看完vue再把springmvc看了的,又只看了部分vue, ...

  7. android提升

    https://blog.csdn.net/lou_liang/article/details/82856531

  8. TLV320AIC3268寄存器读写

    该芯片支持I2C和SPI读写寄存器,本人用的是SPI1接口. 以下是对手册中SPI接口读写寄存器相关内容的翻译(英文版可以看手册的94页~) 在SPI控制模式下,TLV320AIC3268使用SCL_ ...

  9. 解决Django项目静态资源无法访问的问题

    静态资源无法访问 url.py中配置 from django.conf.urls import url from django.views import static from django.conf ...

  10. Gym - 101492I 区间限制费用流

    https://cn.vjudge.net/problem/Gym-101492I 如果用单个点代表每个区间 利用拆点来限制区间的流量的话 点是 n^2/2+m个 边是2*n^2条 但是这样会T 解法 ...