News for hackers. Stuff that matters.
Re:Java Generics FAQs by taeric on Friday April 17, 2015 @09:57AM (#9394291)
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.

There are no comments on this comment yet.