Forwarding this email to weld-dev to make it public
So, the Foo<String> is the required parameterized type here and Foo<E> is parameterized bean type. And from CDI spec[1]: > A parameterized bean type is considered assignable to a parameterized > required type if they have identical raw type and for each parameter: > * the required type parameter is an actual type, the bean type parameter is a > type variable and the actual type is assignable to the upper bound, if any, > of the type variable, or Isn't that the same case? Or am I just running low on caffeine? :) Matej _________________________________________________________________________________ [1] https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#assignable_parameters ----- Original Message ----- > From: "Laird Nelson" <[email protected]> > To: "Matej Novotny" <[email protected]> > Sent: Sunday, April 26, 2020 10:52:57 PM > Subject: Odd type assignability test > > Hello; I ran across this test during some code reading to better understand > type assignability. It's in BeanTypeAssignabilityTest.java: > > @Test > public <E> void testStringFooMatchesVariableFoo() throws Exception { > Type stringFooType = new TypeLiteral<Foo<String>>() { > }.getType(); > Type variableFooType = new TypeLiteral<Foo<E>>() { > }.getType(); > Assert.assertTrue("Foo<String> should match Foo<E>", > getRules().matches(stringFooType, variableFooType)); > } > > Am I reading this right? Is this saying that a reference of type > Foo<String> should be able to receive a Foo<E>, where E doesn't extend > String? > > I understand that any method that declares a type variable E and returns a > Foo<E> will happen to produce a compatible reference. That is: > > public <E> Foo<E> blatz() { /* ... */ } > > can be called like this: > > final Foo<String> foo = blatz(); // should work; E's upper bounds will be > String here > > But in this test, E has no upper bounds, so how does it work? > > Thanks, > Laird > _______________________________________________ weld-dev mailing list [email protected] https://lists.jboss.org/mailman/listinfo/weld-dev
