I'm working in Kotlin and getting a class like such:
val payloadClass = try {
Class.forName("com.something.SomeClass")
} catch (e: ClassNotFoundException) {
null
}
It's successfully finding the class however when I then go to check whether it implements some interface, it keeps returning false
:
To check I'm using the keyword is
:
so payloadClass is AGreatInterface
.
Is there some reason why this wouldn't work. I've used is
elsewhere and it works as expected, wondering if it's something to do with Class.forName
.
I used payloadClass.interfaces.contains(AGreatInterface::class.java)
and that worked. But why wouldn't is
work?
Any ideas appreciated.
Thanks.
(AGreatInterface::class.java).isAssignableFrom(payloadClass)
– Matt Timmermans