3 ms·
In the example case, though, it isn't about giving it a name. It is about using the name in the first place. Is no different from: class Foo { vo
by taeric 12y ago
In the example case, though, it isn't about giving it a name. It is about using the name in the first place. Is no different from:
class Foo {
void test(String arg) {..}
main(..) {
Foo foo = new Foo();
Object s = "sd";
foo.test(s); // Boom
}
}
Note that if that were instead:
class Foo {
void test(Number arg) {..}
main(..) {
Foo foo = new Foo();
Long n = 4L;
foo.test(n);
}
}
Then things work, because the subtyping is chosen. In the generics case, there is no relation between Foo<Number> and Foo<Integer>. If there were, then the capture could potentially treat Foo<?> as Foo<Object> and then depending on if you went co or contra, could allow the call.
- deleted 12y ago[deleted]