samedi 8 octobre 2016

Java Reflection - object graph

I have a problem to solve :) Let's say that I have such structure:

Interfaces:

public interface RestServiceConverter<S, D> {
    public D convert(S input);
}

 

public interface AdvancedRestServiceConverter<D, F, S> extends RestServiceConverter<S, D> {
}

Classes:

public class TestConverter extends SecondAbstractLevel<Integer> {
  @Override
  public ConvertedResult<String> convert(RawResult input) {
    return null;
  }
}

 

public abstract class AbstractTestConverter<S, D> extends SecondAbstractLevel {
}

 

public abstract class SecondAbstractLevel<T>
implements AdvancedRestServiceConverter<ConvertedResult<String>, Integer, RawResult> {
}

Question: is there any simple way to find what types are parameters from RestServiceConverter (look that params are not explicite in this interface but in AdvancedRestServiceConverter in reverse order) starting from TestConverter? Maybe some library can help mi with that. I'm building some functionality in my code, where I have to check if field in some class is same as the second parameter.

Let say I need method like this

findParameter(TestConverter.class, RestServiceConverter.class)

which returns array

[RawType, ConvertedResult<String>]

Thanks for help.





Aucun commentaire:

Enregistrer un commentaire