I'm looking to invoke by reflection a method that returns List<X>. However, I do not have the class definition for X, so I can only get the type by reflection. What's the proper syntax for declaring List<X>, where X is a Class object?
1 Answer
Just use List<Object>, this will work for any object.
1 Comment
m0skit0
@lairtech Just keep in mind that you will be unable to know easily from which class each instance in the list is. This can get very annoying later on. I suggest you rethink your approach, maybe use a base interface or class for the objects held in the
List instead of Object.
List<Object>:-) :-) :-)List<?>rather thanList<Object>as otherwise you could add anything into theList. It depends on the context whether this is an issue. If the method returns a reference to a sharedListit is an issue.