-
-
Save bholota/b50390988323b37d0d29b854f76332c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.support.annotation.IdRes | |
import android.view.View | |
fun <T : View> Activity.bind(@IdRes idRes: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return unsafeLazy { findViewById(idRes) as T } | |
} | |
fun <T : View> View.bind(@IdRes idRes: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return unsafeLazy { findViewById(idRes) as T } | |
} | |
private fun <T> unsafeLazy(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment