Skip to content

Instantly share code, notes, and snippets.

@pokk
Last active July 3, 2017 06:12
Show Gist options
  • Save pokk/81a71cb8c620470bf913df8ef1e90296 to your computer and use it in GitHub Desktop.
Save pokk/81a71cb8c620470bf913df8ef1e90296 to your computer and use it in GitHub Desktop.
the using occasions of lateinit and lazy

[TOC]

Introduction

Introduce that we should use the way of occasions of lateinit and lazy simplely.

lateinit

  1. Import external variable or method, that object is built from external constructor. The lifecycle of self doesn't relate with external object.

lazy

  1. Mainly access the external singleton member, and the lazy init variable will be overed with self object.
val resources by lazy { context.getResources() }

[//]: "lazy 主要使用在外部存取 singleton member 隨著自己類別的生命週期結束"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment