August 2017
Intermediate to advanced
440 pages
10h
English
Some classes in the Android platform use Telescoping constructors, which is considered an anti-pattern. A good example of such a class is the android.view.View class. There may be a case when only a single constructor is used (inflating the custom view from Kotlin code), but it is much safer to override all three constructors when the subclassing android.view.View, because the class will work correctly in all scenarios. Normally, our CustomView class would look like this:
class CustomView : View {
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0) constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, ...Read now
Unlock full access