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

发布于 2024-12-13 10:53:20 字数 987 浏览 1 评论 0原文

我为一个愚蠢的问题道歉;只是无法想出一个合适的术语来搜索。尝试编译第三方源代码时,我遇到了以下编译错误:

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-12-20 10:53:20

如果您使用 PairSet,则 capture#xxx 是泛型类型参数 ? 的占位符。我认为您尝试转换为与实际类型参数不兼容的类型参数。

如果您不知道实际的类型参数,可以先转换为 PairSet,然后再转换为 XT 或 XI。

The capture#xxx is the placeholder for the generic type argument ? if you use 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文