For simplification, I have these two classes:
abstract class ClassA<T> where T : ClassA<T> {
fun fooA(): T {
//Do stuff
return this as T //<-- Cast warning happens here
}
}
open class ClassB : ClassA<ClassB>() {
fun fooB(): ClassB {
//Do stuff
return this
}
}
That line that I have marked in the fooA function gets flagged by IntelliJ with this warning:
"Unchecked cast: ClassA<T> to T"
. Unless I am missing something, the way I have the classes setup should make it impossible for for the return type in function fooA to not be a child of ClassA meaning the cast check would be redundant. Or at least I can't see a way in which fooA could attempt to cast ClassA to something that is not a child of it. Am I missing something, or am I OK to suppress the warning?