0

In the following code, I take a class T as generic "argument" and I need to return something like "T.class" in one of the methods. How do I do it?

public abstract class GenericLogPartitioner<K, V, T extends FileInputFormat<K, V>> extends LogPartitioner {



    @Override
    protected Class<? extends FileInputFormat> getInputFormatClass() {
        return T.getClass(); //what should be here. I need to return T
    }
prongs
  • 9,422
  • 21
  • 67
  • 105
  • 2
    See http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type?rq=1 for why this generally cannot be done in this way. (It may still be possible through stronger reflection or other workarounds.) – Chris Hayes Oct 17 '13 at 05:14
  • You can resolve T using something like [TypeTools](https://github.com/jhalterman/typetools). Class t = (Class)TypeResolver.resolveRawArguments(GenericLogPartitioner.class, getClass())[2]; – Jonathan Oct 21 '13 at 17:10

0 Answers0