In the Kotlin docs, the example shown for calling a generic function looks like this:
fun <T> singletonList(item: T): List<T> {
}
val l = singletonList<Int>(1)
I came across the following code:
val binding = DataBindingUtil.inflate<FragmentPlantDetailBinding>(
inflater, R.layout.fragment_plant_detail, container, false).apply {
}
}
and the inflate method looks like this:
public static <T extends ViewDataBinding> T inflate(@NonNull LayoutInflater inflater,
int layoutId, @Nullable ViewGroup parent, boolean attachToParent) {
return inflate(inflater, layoutId, parent, attachToParent, sDefaultComponent);
}
I thought I understood how calling a generic function works but in the second example, the function has 4 parameters. So what does FragmentPlantDetailBinding refer to? T isn't even being used in the inflate method. It should be noted that the inflate method is Java code while DataBindingUtil.inflate is Kotlin code. Is something going on here when a transition from Kotlin to Java is carried out?
In the Kotlin document example, it is clear that <T> is the type the function is using for both the parameter and the return value. But in that example there is only one parameter, so this is obvious. But if there are multiple parameters, what does it refer to?
T' in the function signature and bodyTis used for the inferred return type