Giter Club home page Giter Club logo

gentyref's People

Contributors

coekie avatar mmerruko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gentyref's Issues

GenericTypeReflector.getExactSuperType fails for static nested (or anonymous) classes

Context
Assume we have an outer class or interface A<X> with type parameters, and a static class B nested in there, which implements this or another generic class/interface C<Y> with a concrete type parameter (e.g. B implements C<String>).

class A<X> {
    static class B implements C<String> {
    }
}
interface C<Y> {}

Wrong behavior
Then GenericTypeReflector.getExactSuperType(B.class, C.class) returns the raw type C

Expected behavior
GenericTypeReflector.getExactSuperType(B.class, C.class) should return the parameterized Type C<String>.

Analysis
In GenericTypeReflector.isMissingTypeParameters (which tries to find out whether we have a (partially) raw type at hand), the loop goes through enclosing classes even if the class itself is static, and thus the type parameters of the enclosing class have no effect on the nested class. It should stop for static nested classes.

Workaround
Put your static nested class into an outer class without type parameters, or make it a top-level class itself.

Generic method with "local" return type will fail to resolve `getExactReturnType`

Hi,

I encountered the following problem:

Given

public class Parent <A> {
  public <T extends Annotation> T getAnnotation(Class<T> clazz) {
    return null
  }
}

public class Child extends Parent<Child> {
}

this call will fail

Method m = Child.getMethod("getAnnotation", Class.class);
GenericTypeReflector.getExactReturnType(m, Child.class);
UnresolvedTypeVariableException: An exact type is requested, but the type contains a type variable that cannot be resolved.
   Variable: T from public java.lang.annotation.Annotation Parent.getAnnotation(java.lang.Class)
   Hint: This is usually caused by trying to get an exact type when a generic method who's type parameters are not given is involved.

The same call does not fail if the containing type is not parameterized.

Method m = Child.getMethod("getAnnotation", Class.class);
GenericTypeReflector.getExactReturnType(m, Class.class);

Furthermore, would it be possible to add a resolveReturnType(Method m, Object[] args) that could return the actual type for such signatures <T extends Annotation> T getAnnotation(Class<T> clazz) when the arguments are given?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.