Skip to content

Commit

Permalink
update Kotlin lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 29, 2017
1 parent 48aa302 commit 3536106
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Lazy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ package com.betterzhang.learnkotlin.kotlin
*/

class Lazy {

private var name1: String? = null
private var name2: String = ""

// lateinit是用来告诉编译器,name 这个变量后续会妥善处置的
private lateinit var name3: String

companion object {
val lazyValue: String by lazy {
println("init") // 第一次使用时才被初始化
Expand Down

0 comments on commit 3536106

Please sign in to comment.