How to get class object of a generic interface? For example, Boolean.class, Date.class. But List<Boolean>.class doesn't seem to be syntax-valid.
Just write List.class. List<Boolean> is not of a different type, at runtime. The generic type only exists at compile time. So this imaginary List<Boolean>.class would not exist to be used in your program.
There is no way to programmatically access the generic type, since it is not present in the byte code. It is only to help the compiler.
Due to type erasure, your List<Boolean> will be converted to a simple raw List at runtime, thus, your best bet is to use List.class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With