What is “A” here? ``` fun <T : ViewModel, A>...
# getting-started
s
What is “A” here?
Copy code
fun <T : ViewModel, A> singleArgViewModelFactory(constructor: (A) -> T):
        (A) -> ViewModelProvider.NewInstanceFactory {
    return { arg: A ->
        object : ViewModelProvider.NewInstanceFactory() {
            @Suppress("UNCHECKED_CAST")
            override fun <V : ViewModel> create(modelClass: Class<V>): V {
                return constructor(arg) as V
            }
        }
    }
}
r
It's a generic type. The function defines two generic types:
fun <T: ViewModel, A> ...
T
, which must be subtype of
ViewModel
, and
A
, which can be anything.
👍 2
p
It's the type of the parameter of the constructor you supply. Or - more succinctly, it is the type of the single arg.