xvik / generics-resolver

Java generics runtime resolver
https://xvik.github.io/generics-resolver
MIT License
46 stars 9 forks source link

Resolving generic type bounds to a j.l.r.Type, not a j.l.Class? #4

Closed pholser closed 5 years ago

pholser commented 5 years ago

Hello, thanks again for your magnificent work.

I'm using generics-resolver 3.0.0 in junit-quickcheck, and am trying to resolve an issue with it that a user raised.

Given this class:

    @RunWith(JUnitQuickcheck.class)
    public static class GenericMethodVars {
        @Property
        public <X extends HashMap<Integer, Character>> void x(
            Callable<X> callable) {

            System.out.println(callable);
        }
    }

junit-quickcheck will do something like this to resolve the variables to some type:

        MethodGenericsContext generics =
            GenericsResolver.resolve(GenericMethodVars.class)
                .method(GenericMethodVars.class.getMethod("x", Callable.class));
        Map<String, Type> typeVariables = generics.genericsMap();
        typeVariables.putAll(generics.methodGenericsMap());

I was hoping that type variable X would be associated with a parameterized type HashMap<Character, Integer>. Instead it's associated with the java.lang.Class object for java.util.HashMap.

Am I doing something incorrect? Can I accomplish what I want using generics-resolver?

xvik commented 5 years ago

Hello!

It's my bad.. I did not face such cases myself, and so this part remains not updated for a long time.. I indeed loose type information there. The same problem with constructor contexts.

I was preparing new 3.1.0 version with a lot of changes.. but it's not ready now for publication (I did not check everything). So instead, I will release 3.0.1 hotfix (hopefully today).

xvik commented 5 years ago

New version is released, but only in jcenter because central's nexus is dying since yesterday. New version will appear in central as soon as it will become responsible.

xvik commented 5 years ago

Finally, central accept publication. Version will appear soon.