Kotlin黑魔法:Delegated Properties - Shieh Npin === > 請從這裡開始 ## Property * 物件的屬性,透過 Setter 和 Getter 定義 * 不是 filed ,實際上由 function 組成 * 避免重複定義 function * 避免產生遞迴 * get() = field * 可用 Extention Function 增加 property ## Delegate * 名稱不會被父類別限制 * 可在 runtime 改變實作 ## Delegate Property * var/val prop:Type by DelegateObject() ## Build-in Delegate Property * by notnull * by map * property 會被委派給 map 中同名 key 值 * lazy * lazy * thread safe * Observable ## Custom Delegate Property * bindView(...) * View and Resource Binding * Data Binding * SharedPreference * DI ## Custom Delegate Property範例 * 使用時機 -> 相似的模式 * ###### tags: `DevFest2019`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up