[LANG3] Issue with TypeUtils.isAssignableTo() using JDK ParameterizedType

Sunny Chan <[email protected]> Thu, 30 May 2024 16:16:23 +0100
Newsgroups gmane.comp.jakarta.commons.user
Message-ID <CAFf03q3zq1am4RG5QH=jP4N9L+7-aqr8gX7jbf257Hv=Gz3KcQ@mail.gmail.com>
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