Groovy已弃用的方法和Eclipse - 排序 [英] Groovy Deprecated Methods and Eclipse - sort

查看:165
本文介绍了Groovy已弃用的方法和Eclipse - 排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我在groovy中写了1.8

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

我已经移动到了2.3.x和eclipse(使用e4.4 GroovyEclipse插件对于Juno从快照版本)显示我现在对于 sort(Collection< T> self)已经不推荐使用sort()方法, sort(Iterable< T> self)



如何将这样的方法链接在一起以避免弃用警告?



我的想法是,flatten()返回一个ArrayList(这是一个Iterable )应该没关系另外,我看到这样做

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

删除警告,但看起来很丑陋。



这是只是日食没有看到正确的排序实际上会被使用,还是有其他方式表达我的方法链?

解决方案

废弃警告是由于Eclipse将Groovy方法映射到大部分不推荐使用的DefaultGroovyMethods类,而这些类已被许多单独的其他类替换,如StringGroovyMethods,ResourceGroovyMethods等。



似乎在版本 Groovy插件的2.7.1 ,这是固定的...检查你的版本的插件,也许你只需要升级。



如果这不能解决问题,不幸的是,除非你可以使Groovy插头在改变方法映射的时候,你将无法摆脱警告,据我所知。在IntelliJ我也有同样的问题。


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?

解决方案

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.

这篇关于Groovy已弃用的方法和Eclipse - 排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆