0

After following a Slick2D tutorial on custom fonts, it provided me with the following code to initialise it:

titleFont.addAsciiGlyphs();
titleFont.addGlyphs(400, 600);
titleFont.getEffects().add(new ColorEffect()); //Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized
titleFont.loadGlyphs();

Eclipse throws the commented warning on that line. Can you please answer with a replacement to line 3 with whatever Eclipse is asking me to put in there.

njallam
  • 476
  • 9
  • 23
  • I believe this has to do with type erasure, see this: http://stackoverflow.com/questions/1356382/java-list-parameterized – anio Aug 27 '12 at 17:21
  • Is there nothing specific to Slick2D I can do? I really don't like the idea of suppressing a warning and have no clue what I need to add (That's the whole point of this question.) – njallam Aug 27 '12 at 17:25

1 Answers1

0

That warning is telling you the list returned by getEffects() is not parameterized. It is of type List. Since that list is inside the Slick library, you can't really do anything about that warning. Just carry on.

Here is the source code, I'm guessing you are using Unicode font: https://bob.newdawnsoftware.com/repos/slick/trunk/Slick/src/org/newdawn/slick/UnicodeFont.java

You can see for yourself that the effects are stored in a List rather than being parameterized.

I was wrong in my initial comment, the error isn't because of type erasure, its because the effects list is raw. See this: What is a raw type and why shouldn't we use it?

Community
  • 1
  • 1
anio
  • 8,903
  • 7
  • 35
  • 53
  • So there is nothing I can do aside from suppressing the error? – njallam Aug 27 '12 at 17:35
  • Short of modifying the source code? No. You could report the warning to Kevin, or better yet, submit a patch. It is an easy fix and you'll feel good about your community service. :) – anio Aug 27 '12 at 17:37
  • All effects implement ConfigurableEffect interface, I think you just need to change List effects to be: List. – anio Aug 27 '12 at 17:40
  • I'm not sure whether the project is still being actively maintained. Also, how would I go about submitting a patch? I've never done that before. – njallam Aug 27 '12 at 17:44
  • The project is definitely actively maintained. Just post the patch on the slick2d forums. They are very friendly over there. You'll find help for all your slick2d woes there. – anio Aug 27 '12 at 17:46
  • If you'd rather do it, then go ahead. It was your find and I have no clue how to fix it still. – njallam Aug 27 '12 at 17:53