So the issue is this:

Type assignFrom = TypeUtils.parameterize(Container.class, Integer.class);
Type assignToUsingTypeUtils = TypeUtils.parameterize(Container.class, 
String.class);
Type assignToUsingReflection = 
constructors[0].getGenericParameterTypes().parameters[0];

TypeUtils.isAssignable(assignFrom, assignToUsingTypeUtils) // this return false;
TypeUtils.isAssignable(assignFrom, assignToUsingReflection) // this return true;


On 2024/05/30 15:40:35 Matt Benson wrote:
> I am confused as to what could be wrong with determining that
> Container<String> is *not* assignable to Container<Integer>. But are you
> saying that the manually constructed parameterized Type *is* reported as
> being assignable despite the obviously incompatible type parameters?
> 
> Matt
> 
> On Thu, May 30, 2024, 10:31 AM Sunny Chan <[email protected]>
> wrote:
> 
> > I have an issue with TypeUtils.isAssignableTo and I would like to check
> > whether this is expected or a bug.
> >
> > Consider we have a number of classes
> >
> > class Container<A> {.......}
> >
> > class ParameterizedConstructor<String> {
> >    //consturctor that takes a container
> >    public ParameterizedConstructor(Container<String> input) {..}
> > }
> >
> > Then if I use TypeUtils to create some parameterized type for checking
> > purposes:
> >
> > //The following will give you TypeVariable with Container<String>
> > var constructors = ParameterizedConstructor.class.getConstructors();
> > var parameters = constructors[0].getGenericParameterTypes();
> > Type assignableTo = parameters[0];
> >
> > // I want to check whether we can do a equals
> > Type assignFrom = TypeUtils.parameterize(Container.class, Integer.class);
> >
> > //If you run this with lang 3 it will return true but I get a false here :
> > TypeUtils.isAssignable(assignFrom, assignTo)
> >
> > Notice that if I use TypeUtils factory to create the parameterize type, it
> > will return correct behaviour
> >
> > I am wondering whether we expect ParameterizedType from JDK is not expected
> > to work here?
> >
> > Thanks
> >
> 
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to