Search code examples
javalistjmonkeyengine

Problems with Lists and ImmutableLists


So I have this weird error in my program (The last error before there is supposedly no more) that I cannot solve no matter what I do. I am using jMonkey Engine 3 (jme3) and this is the piece of code with the error:

public List<Element> getTerrainElements() {
    return ImmutableList.builder().addAll(this.elements).build();
  }

and the error is this:

incompatible types
required: List<Element>
found:    ImmutableList<Object>

No matter what I try on this bit of code I always get an error and I want to knnow how to get rid of the error so I can start to debug my program. If any more information is needed to answer my question, just ask and I will be glad to tell you anything I can. Thanks!


Solution

  • You need to do

    return ImmutableList.<Element>builder().addAll(this.elements).build();
    

    instead.

    ImmutableList.builder() is not able to infer the generic type, so you need to specify it explicitly.