为什么我在Groovy Eclipse IDE中收到”已弃用”警告,而在IntelliJ IDEA中却没有收到?

Why I receive “Deprecated” warning in Groovy Eclipse IDE but not in IntelliJ IDEA?

我最近才开始学习Groovy,并且我注意到,在Groovy Eclipse中,对集合(例如列表)的min()和max()方法调用总是被删除为" Deprecated "。警告消息建议我最好使用" iterable "版本。

我不了解的是列表实现了可迭代的接口,因此它已经是可迭代的了。

(顺便说一句,我使用的是编译器级别2.4)

同一代码在IntelliJ IDEA中未收到任何警告。

问题:该警告是否合法?如果是,那怎么办?还是IDE有问题?

1
2
def list = [1, 2, 3, 4];
print list.max();

我什至更改了变量声明,如下所示:

1
List list = [1, 2, 3, 4];

但是仍然收到" Deprecated "警告。


我说,这是IDE的问题。看看这个:

1
2
3
4
5
6
7
8
9
10
11
import groovy.util.GroovyCollections

GroovyCollections.methods
    .findAll { it.name == 'max' }
    .collect {
        [
            name: it.name,
            parameters: it.parameterTypes,
            annotations: it.declaredAnnotations
         ]
     }.inspect()

上面代码的输出是...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[
    [
        'name':'max',
        'parameters':[interface java.util.Collection],
        'annotations':[@java.lang.Deprecated()]
    ],
    [
        'name':'max',
        'parameters':[interface java.lang.Iterable],
        'annotations':[]
    ],
    [
        'name':'max',
        'parameters':[class [Ljava.lang.Object;],
        'annotations':[]
    ]
]

首先,我应该提到GroovyCollections是或可以用作Groovy类别。因此,通常不以上述方式使用它。

A CollectionIterable。因此,在此变更集中不赞成使用Collection.max(),而推荐使用Iterable.max()。票在这里。

因此,看来Eclipse有点混乱。