0

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!

1Poseidon3
  • 125
  • 1
  • 11

1 Answers1

3

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.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
  • So far the error is not showing up so I will debug really quickly and ill be back but so far this worked! :D – 1Poseidon3 Feb 28 '14 at 02:42
  • Answer given by @lae is correct but I would like to share my experience.I generally use the ImmutableList.copyOf() static factory method as it is a nice clean generic factory method – Abhijeet Kushe Feb 28 '14 at 03:10