Details
-
Bug
-
Resolution: Duplicate
-
P4
-
9
Description
This should compile, does not:
interface I<X> {}
<T> T make(I<T> ts) { return null; }
<E extends CharSequence> E take(I<? extends E> arg) { return null; }
void test(I<I<? extends String>> arg) {
take(make(arg)).intern();
}
Inference succeeds, with E=CharSequence. The call to 'intern' then fails. Expected: infer E=String.
Walking through expected inference behavior:
Applicability inference for 'make':
I<I<? extends String>> --> I<t>
{ t = I<? extends String> }
Applicability inference for 'take':
make(arg) --> I<? extends e>
t --> I<? extends e>
{ t = I<? extends String>, t <: I<? extends e>, e <: CharSequence }
Incorporation:
I<? extends String> <: I<? extends e>
{ t = I<? extends String>, t <: I<? extends e>, String <: e, e <: CharSequence }
Resolution:
e = String, t = I<? extends String>
interface I<X> {}
<T> T make(I<T> ts) { return null; }
<E extends CharSequence> E take(I<? extends E> arg) { return null; }
void test(I<I<? extends String>> arg) {
take(make(arg)).intern();
}
Inference succeeds, with E=CharSequence. The call to 'intern' then fails. Expected: infer E=String.
Walking through expected inference behavior:
Applicability inference for 'make':
I<I<? extends String>> --> I<t>
{ t = I<? extends String> }
Applicability inference for 'take':
make(arg) --> I<? extends e>
t --> I<? extends e>
{ t = I<? extends String>, t <: I<? extends e>, e <: CharSequence }
Incorporation:
I<? extends String> <: I<? extends e>
{ t = I<? extends String>, t <: I<? extends e>, String <: e, e <: CharSequence }
Resolution:
e = String, t = I<? extends String>
Attachments
Issue Links
- duplicates
-
JDK-8160244 skip capture conversion before subtyping if types are parameterizations of the same class or interface
- Open
- relates to
-
JDK-8033718 Inference ignores capture variable as upper bound
- Closed
-
JDK-8016196 Inference: define supertype parameterization for wildcard-parameterized types
- Open
-
JDK-8155072 Type inference regression
- Resolved