I am using ViewModelFactory in my android app to pass some data to my ViewModel from Fragment. I'm getting unchecked cast warning. If I'm using Supress the warning goes away. I was wondering is there any way to handle this without using Supress("UNCHECKED_CAST")
The code I'm using to create the ViewModelFactory
val factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory {
//factory to pass necessary data to ViewModel
@NonNull
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return activity?.application?.let {
BookReaderViewModel(
it,
"local",//todo:remote or local book. value will come from arguments
1//todo: bookId will come from arguments
)
} as T
}
}
as T is getting the warning.