0

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?

2
  • 5
    It's List<Object> :-) :-) :-) Commented May 5, 2014 at 14:50
  • Actually, it’s List<?> rather than List<Object> as otherwise you could add anything into the List. It depends on the context whether this is an issue. If the method returns a reference to a shared List it is an issue. Commented May 5, 2014 at 15:04

1 Answer 1

1

Just use List<Object>, this will work for any object.

Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.