[TOC]
Ruby and Kotlin have the same magic candy function!
- apply (also)
| @Singleton | |
| @Component(modules = arrayOf(AppModule::class, | |
| RepositoryModule::class, | |
| BindingActivityModule::class, | |
| AndroidSupportInjectionModule::class)) | |
| interface AppComponent : AndroidInjector<App> { | |
| /** [AndroidInjector] Builder for using on this whole app. */ | |
| @Component.Builder | |
| abstract class Builder : AndroidInjector.Builder<App>() |
| override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | |
| // Measure all of children's width & height. | |
| this.measureChildren(widthMeasureSpec, heightMeasureSpec) | |
| // Measure width & height of this view_group's layout(layout_width or layout_height will be `match_parent` | |
| // no matter what we set `wrap_content` or `match_patent` when we're using getDefaultSize). | |
| // We'll reset this method by another way for achieving `wrap_content`. | |
| val mini = minOf(getDefaultSize(suggestedMinimumWidth, widthMeasureSpec), getDefaultSize(suggestedMinimumHeight, heightMeasureSpec)) | |
| this.setMeasuredDimension(mini, mini) | |
| } |
| // There is a class with generic parameter. | |
| abstract class A<T> { | |
| // This is KClass version. | |
| val t: T by lazy { | |
| (this@A::class | |
| .supertypes.first() // KType of A class | |
| .arguments.first() // Data type of the generic T | |
| .type!!.classifier as KClass<*>) // The class of the generic T | |
| .primaryConstructor!!.call() as T // An object from the generic T | |
| } |
| // A class | |
| fun caller() { | |
| // here we will set callback function. | |
| callbackProcessor.subscriby { | |
| // Here I can get `5566`, and do somthing. | |
| } | |
| } | |
| // B class | |
| fun callee() { |