6

I've got the following code which I wrote in groovy 1.8

someListOfLists.flatten().sort().unique()

I've moved over to groovy 2.3.x, and eclipse (using e4.4 GroovyEclipse plugin for Juno from snapshot release) is showing me the sort() method is now deprecated for sort(Collection<T> self), to which the advice is to use the sort(Iterable<T> self).

How do I now chain methods like this together to avoid the deprecation warnings?

My thinking was that as flatten() is returning an ArrayList (which is an Iterable) it should be fine. Also, I see doing

((Iterable) someListOfLists.flatten()).sort().unique()

removes the warning, but looks ugly.

So is this just eclipse not seeing that the correct sort will actually be used, or is there some other way to express my chain of methods?

Mark Fisher
  • 9,838
  • 3
  • 32
  • 38

1 Answers1

6

The deprecation warnings are due to the fact that Eclipse is mapping Groovy methods to the mostly deprecated DefaultGroovyMethods class, which was just replaced by many separate other classes such as StringGroovyMethods, ResourceGroovyMethods etc.

It seems that in version 2.7.1 of the Groovy plugin, this was fixed... check your version of the plugin, maybe you just need to upgrade.

If that does not solve the problem, unfortunately, unless you can make the Groovy plugin change the methods mapping, you won't be able to get rid of the warnings, as far as I know. In IntelliJ I have the same problem.

Renato
  • 12,940
  • 3
  • 54
  • 85
  • 1
    The GRECLIPSE snapshot version I'm using is 2.9.1. I think the particular fix mentioned in your link is just for tokenize(). I'll just live with it for now and maybe ask on their forums if it occurs in too much of my code, or unless someone else comments on this. Cheers. – Mark Fisher Sep 30 '14 at 10:27
  • I'm using Groovy Eclipse plugin 2.9.1 and I have a similar error - http://stackoverflow.com/questions/28474559/why-is-list-sort-method-striked-through . – Glory to Russia Feb 12 '15 at 10:21