Skip to content
Advertisement

Get generic type of java.util.List

I have;

JavaScript

Is there a (easy) way to retrieve the generic type of the list?

Advertisement

Answer

If those are actually fields of a certain class, then you can get them with a little help of reflection:

JavaScript

You can also do that for parameter types and return type of methods.

But if they’re inside the same scope of the class/method where you need to know about them, then there’s no point of knowing them, because you already have declared them yourself.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement