Search code examples
javagradlebuild.gradleminecraftminecraft-forge

Java "error: incompatible types: inference variable E has incompatible bounds" error


So i am trying something out in java. (a forge minecraft mod). And when i compile, i keep getting this error:

error: incompatible types: inference variable E has incompatible bounds
    return Lists.newArrayList((Object[])new String[] { "clickset" });
                             ^
    equality constraints: String
    lower bounds: Object
  where E is a type-variable:
    E extends Object declared in method <E>newArrayList(E...)

The code is:

public List<String> getCommandAliases() {
    return Lists.newArrayList((Object[])new String[] { "clickset" });
}

Solution

  • That line is rather obviously broken: It calls Lists.newArrayList, which is presumably guava's Lists utility class (is there an import com.google.common.collect.* or .Lists at the top? Then, yes). Even if it isnt, the name makes the intent clear.

    You hand this method an Object[] (because of the cast). Obviously, that means it will return a List<Object>. Your method, however, must return a List<String>. It doesn't, thus, error.

    This code does not work now and never has.

    If you want it to work, remove the (Object[]), I have no idea who added it, or why. Possibly this is code produced by decompiling some class files. It's extremely common for those to not actually be fully valid. If you did that to more than a few pagefuls of code, this is merely the first in about 149495581 further errors.