How do I store the results of a variable call if it returns Class<?>[]? This is generics at work I assume but I can’t figure out how to store it.
for example when i do
myObject. -> here i get the list of methods in eclipse, when i go to the method i want it returns Class<?>[]
I think the questions shows a misconception with generics.
When a method returns
that’s because you made it so it can return an array of any type of class.
When you actually use the method, it doesn’t evaluate what the real Classes are, it just returns what was declared in the method signature. You can then check for each object you have in your result, and get the actual class. Generics is only a way to make weakly typed general classes (i.e. collections) a bit more strongly typed, it’s not a processing mechanism. It will never find out what the
?is for you.If you know in advance what the
?might be, change your method signature to indicate it. You can even declare it as something liketo indicate that you expect only subclasses of BaseClass.