2

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?

Community
  • 1
  • 1
alf
  • 8,377
  • 24
  • 45
  • 3
    The capture#xxx is the placeholder for the `?` if you use `PairSet,?>`. I think you try to cast to a type parameter that is incompatible with the actual type parameter. – Stephan Oct 31 '11 at 17:38
  • @Stephan -- could you post that as an answer rather than a comment? Then maybe alf could accept it and this question would come off the unanswered list. – David Moles Mar 07 '12 at 19:07
  • @Stephan - confirmed, will be happy to accept. – alf Mar 07 '12 at 21:52

1 Answers1

1

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.

Stephan
  • 4,395
  • 3
  • 26
  • 49