Prototype Factory
About Archive Photos Also on Micro.blog
  • Nutcracker at The Four Seasons Center in Toronto

    → 6:57 PM, Dec 21
  • Actual generic parameters of a Class in runtime

    Yesterday I was working on dynamic mapping of marshallers to their marshalled type. The way I’ve done it was having an interface Marshaller with generic parameter <T>. Then I was using Reflections to get all classes that implements this interface. Then I needed to get the actual type of <T> which is a problem if there is for example an abstract class that is the base for all marshallers. So if you have the following setup, it’s not as easy as just calling ParameterizedType#getActualTypeArguments().

    interface Marshaller<T> {
    	... 
    }
    
    abstract class AbstractMarshaller<T> implements Marshaller<T> {
    	...
    }
    
    class BooleanMarshaller extends AbstractMarshaller<Boolean> {
    	... 
    }
    

    So I have written the following method that resolves actual types of all generic parameters of a given class.

    Continue reading →

    → 12:00 AM, Apr 11
  • RSS
  • JSON Feed
  • Surprise me!