this is pretty much the code setup:
// java
public class JavaA {
}
// scala
class ScalaA() extends JavaA {
}
but then in java, if i have an instance of ScalaA somewhere (or even if its null), but try to do this:
ScalaA scalaA = ...
if (scalaA instanceof JavaA) { ... }
on the line with instanceof, intellij doesn't show any error. but if i try to compile the code, i get the java: incompatible types
i've included the scala sdk as a project depedency, the java versions are correct, ive tried invalidating the cache/restarting, etc, but it doesnt seem to work. does anyone know how to fix this?
also, the scala class, it's compiled in a .jar file, and i imported it as a dependency. just like with the scala SDK and stuff
edit: i found a "solution" that seems to work; its not really a fix, but it works for now. i basically just used a function called "forceCast", and the code looks like this:
public static <T> T forceCast(Object value) {
try {
return (T) value;
}
catch (Exception e) {
return null;
}
}
and then
ScalaA scalaA = ...
JavaA javaA = forceCast(scalaA);
realistically, an exception should never be thrown in this case. this actually did fix my issue, and let me compile the code. im not sure about using instanceof, but i guess what i could do is just cast scalaA to an object, and do it that way