简体   繁体   English

错误消息中的capture#XXX(Java泛型)

[英]capture#XXX in error message (Java Generics)

My apologies for a silly question; 我对一个愚蠢的问题表示歉意; just cannot come up with a proper term to search for. 只是无法提出合适的搜索条件。 Trying to compile a third-party sources, I've bumped into the following compilation error: 尝试编译第三方源时,我遇到了以下编译错误:

/Users/alf/Work/concise.svn/ExtendedSet/src/it/uniroma3/mat/extendedset/transactions/PairSet.java:[230,28] inconvertible types
found   : java.util.Collection<capture#741 of ? extends it.uniroma3.mat.extendedset.transactions.Pair<XT,XI>>
required: it.uniroma3.mat.extendedset.transactions.PairSet<XT,XI>

I guess I know what is the problem—but what does capture#741 mean? 我想我知道是什么问题,但是capture#741是什么意思? Each time I'm trying to recompile, the number after # changes—not sure if it helps in any way. 每次尝试重新编译时, #后面的数字都会更改-不确定是否有任何帮助。

Update: 更新:

The code in question was, 有问题的代码是,

public static <XT, XI> PairSet<XT, XI> newPairSet(Collection<? extends Pair<XT, XI>> ps, boolean compressed) {
    if (ps instanceof PairSet)
        return (PairSet<XT, XI>) ps;

and the fix suggested in javac error: inconvertible types with generics? 以及javac错误中建议的修复方法:具有泛型的不可转换类型? works just fine—but what does capture#741 mean? 正常工作-但是capture#741是什么意思?

The capture#xxx is the placeholder for the generic type argument ? capture#xxx是通用类型参数的占位符? if you use PairSet<?,?> . 如果使用PairSet<?,?> I think you try to cast to a type parameter that is incompatible with the actual type parameter. 我认为您尝试转换为与实际类型参数不兼容的类型参数。

If you do not know the actual type argument, you can cast to PairSet and cast to XT or XI later. 如果您不知道实际的类型参数,则可以PairSetPairSet并稍后PairSet为XT或XI。

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

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