Scala

Scala

Made by DeepSource

Missing type parameter for cast operations SC-W1075

Bug risk
Critical

Methods such as .isInstanceOf and .asInstanceOf allow you to check if an entity belongs to a certain type and cast an entity to a specified type respectively. Both these methods take in a type parameter T. Failing to specify this type parameter may permit compilation but will result in a java.lang.ClassCastException exception. It is recommended that you specify this type parameter.

Bad Practice

val isFoo = e.isInstanceOf // always evalutes to false
val foo   = e.asInstanceOf // results in `java.lang.ClassCastException`

Recommended

val isFoo = e.isInstanceOf[Foo]
val foo   = e.asInstanceOf[Foo]