捕获错误消息中的#XXX(Java 泛型)
我为一个愚蠢的问题道歉;只是无法想出一个合适的术语来搜索。尝试编译第三方源代码时,我遇到了以下编译错误:
/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>
我想我知道问题是什么,但是 capture#741
是什么意思?每次我尝试重新编译时,#
后面的数字都会发生变化 - 不确定它是否有任何帮助。
更新:
有问题的代码是,
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;
以及 javac error: inconvertible types with generics 中建议的修复? 工作得很好,但是 capture#741
是什么意思?
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? 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? works just fine—but what does capture#741
mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
PairSet
,则 capture#xxx 是泛型类型参数?
的占位符。我认为您尝试转换为与实际类型参数不兼容的类型参数。如果您不知道实际的类型参数,可以先转换为
PairSet
,然后再转换为 XT 或 XI。The capture#xxx is the placeholder for the generic type argument
?
if you usePairSet<?,?>
. 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.