繁体   English   中英

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

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

我最近才开始学习Groovy,我注意到在Groovy Eclipse中,对集合(例如列表)的min()和max()方法调用总是被删除为“不推荐使用”。 警告消息建议我最好使用“可迭代”版本。

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

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

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

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

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

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

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

但是仍然会收到“已弃用”警告。

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

import groovy.util.GroovyCollections

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

上面代码的输出是...

[
    [
        '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类别。 因此,通常不以上述方式使用它。

Collection 是可 Iterable 因此,在变更集中不推荐使用Collection.max()而推荐使用Iterable.max() 票在这里

因此,看来Eclipse有点混乱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM