how can we create an extension or infix function for
!is
to use it like`someVar isnot String`?
d
Dominaezzz
12/29/2021, 12:54 PM
Not possible.
String
cannot be passed as a value. Unless you're okay with
someVar isnot String::class
?
s
Sergio C.
12/29/2021, 12:57 PM
too bad.
but I mean String as an example, I wanted to use it with any generic class
d
Dominaezzz
12/29/2021, 12:58 PM
Copy code
public inline infix fun <reified T : Any> Any?.isnot(ignored: KClass<T>): Boolean {
return this !is T
}
public fun test() {
val lol: Any = "Some stuff"
if (lol isnot String::class) {
println("Yay!")
}
}