Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Last active February 28, 2017 14:04
Show Gist options
  • Save danielgomezrico/e51337945d9277e6c5ad95e1abe33daf to your computer and use it in GitHub Desktop.
Save danielgomezrico/e51337945d9277e6c5ad95e1abe33daf to your computer and use it in GitHub Desktop.
Android / Kotlin - Using @jvmoverloads tag to avoid multiple "empty" constructors for inheritance (shown with custom android views). (thanks to https://discuss.kotlinlang.org/t/simple-constructors-for-inheritance/1874/2)
class MyCustomView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0)
: FrameLayout(context, attrs, defStyleAttr){
init {
// ...
}
}
class MyCustomView : FrameLayout {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int)
: super(context, attrs, defStyleAttr) {
init()
}
fun init() {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment