简体   繁体   中英

Compile errors in IntelliJ but not in eclipse

I'm switching to IntelliJ IDEA from Eclipse and i get compile errors in IntelliJ, but not in eclipse.

public class TestClass<K, V extends Comparable<V>> {

private K key;
private V value;

public void someMethod() {
    if (this.value instanceof String) {
        String stringValue = (String) this.value;
        // some code
    }
}
}

(dont blame me for that code, it's legacy code and not mine)

In eclipse everything is fine, in intellij it is marked as an error which says "inconvertible type, cannot cast V to java.lang.String".

For both i use my standard MacOS X JDK (1.6.0_65).

It's not only with String, it's with every type/class (i have some other concurrents of this)

Why do i get these errors in intellij but not in eclipse?

Java's String class is final, there is no way that your this.value inherits from it. You should use .toString() or String.valueOf() to avoid the casting.

You see the phenomenon because Eclipse compiler is different from javac (that used by default in IntelliJ, but you can change that). Eclipse compiler is more permitting. See this question for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM