Verify Generics
// Example 1: Class
// Here 'T' is a TYPE PARAMETER
class Box<T>(val item: T)
// Here 'String' is a TYPE ARGUMENT
val stringBox = Box<String>("Hello")
// Example 2: Function
// Here 'T' is a TYPE PARAMETER
fun <T> printWithType(item: T) {
println("Type is: ${item::class.simpleName}")
}
// Here 'String' and 'Int' are TYPE ARGUMENTS
printWithType<String>("Hello") // prints: Type is: StringVerify Type Parameters
Check whether a class's generic type parameter has the name UiState:
UiState:Check whether function type parameters has out modifier:
type parameters has out modifier:Verify Type Arguments
Check whether a property generic type argument has the name Service:
Service:Check if all functions parameters are have generic type argument ending with UIState:
UIState:Check all parents have `String` type argument:
Last updated