Can someone explain, please, why i can't do the code below from Java in Kotlin?
Java:
public static <T extends ViewGroup> void doSomething(T viewGroup) {
T.LayoutParams params = viewGroup.getLayoutParams();
}
Kotlin:
fun <T : ViewGroup> doSomething(viewGroup: T) {
val params : T.LayoutParams = viewGroup.layoutParams
}
or
fun <T : ViewGroup> T.doSomething() {
val params : T.LayoutParams = this.layoutParams
}
Kotlin just doesn't see LayoutParams.
T.LayoutParamsdoes not have a well-defined semantics (other than saying "At execution timeTis replaces with its upper boundViewGroup). The "correct" (and more reabable way) would be to useViewGroup.LayoutParams.T.LayoutParamsmeans justViewGroup.LayoutParams. If one of subtypes ofViewGrouphas its ownLayoutParamsclass defined, it won't be used.