Open hym1224 opened 6 years ago
学习 Kotlin 的 20 个实用资源 https://zhuanlan.zhihu.com/p/27300530
kotlin in action https://panxl6.gitbooks.io/kotlin-in-action-in-chinese/
备用字段
总结下来,对其理解就是 具备后备字段的属性。其实就是类中自己的属性。可读可写。 而不具备后备字段的属性,其实是一个代理?可读不可写。
Kotlin's Iterable and Sequence look exactly same. Why are two types required?
Where Should I Keep My Constants in Kotlin?
https://blog.egorand.me/where-do-i-put-my-constants-in-kotlin/
Java 8 Stream API Analogies in Kotlin
Exploring Kotlin’s hidden costs
Kotlin スコープ関数 用途まとめ https://qiita.com/ngsw_taro/items/d29e3080d9fc8a38691e
1:声明属性并在主构造函数中初始化,在 Kotlin 中有更简单的语法:
2: apply vs with apply函数是这样的,调用某对象的apply函数,在函数范围内,可以任意调用该对象的任意方法,并返回该对象 when to use, which to use Usually you use apply when you need to do something with an object and return it. And when you need to perform some operations on an object and return some other object you can use with.
3:使用命名参数我们可以让代码可读性更强
4:kotlin调用java代码 ( getClass() ) To retrieve the Java class of an object, use the java extension property on a class reference:
The code above uses a bound class reference, which is supported since Kotlin 1.1. You can also use the javaClass extension property:
5:!! 操作符 第三个选择是 NPE-lovers。我们可以用 b!! ,这会返回一个非空的 b 或者抛出一个 b 为空的 NPE
6:inline keyword from https://stackoverflow.com/questions/44471284/when-to-use-an-inline-function-in-kotlin
7:run run函数和apply函数很像,只不过run函数是使用最后一行的返回,apply返回当前自己的对象。 from https://www.jianshu.com/p/5c4a954d2b2c
8:Reified Types from https://antonioleiva.com/reified-types-kotlin/ https://blog.simon-wirtz.de/kotlin-reified-types/
9:lateinit & lazy 该修饰符只能用于在类体中的属性(不是在主构造函数中声明的 var 属性,并且仅当该属性没有自定义 getter 或 setter 时),而自 Kotlin 1.2 起,也用于顶层属性与局部变量。该属性或变量必须为非空类型,并且不能是原生类型。
在初始化前访问一个 lateinit 属性会抛出一个特定异常,该异常明确标识该属性被访问及它没有初始化的事实。
lazy() 是接受一个 lambda 并返回一个 Lazy 实例的函数,返回的实例可以作为实现延迟属性的委托: 第一次调用 get() 会执行已传递给 lazy() 的 lambda 表达式并记录结果, 后续调用 get() 只是返回记录的结果。
from https://mindorks.com/blog/learn-kotlin-lateinit-vs-lazy
10:object 对象表达式,对象声明,单例模式
11:Extension Functions
12:Data Class