Hi all. My program accesses a service that returns a List<DeliveryCalendarDay<?>>, where DeliveryCalendarDay is a generic object to be parameterized with a specific calendar. My problem is that I have trouble using the actual objects from the list- I can't seem to find a way to tell the compiler that yes, I know what type of objects they are, so it's okay to let me access the methods. I've tried to read about wildcard parameterizations (it's very confusing to me!) and the only information I've found on this question (as far as I could understand what I read, anyway) is that it's a bad idea for methods to return such things. That doesn't help me, though- is there a way around this? Thanks!
The compiler is not going to stop you from doing that. What you see when you compile is a warning, not an error.
You can still execute the program, but the compiler is warning you that it can't guarantee type safety.
If you don't want to see the warning, you can use the annotation @SuppressWarnings("unchecked") in JDK 1.5.0_06 or greater.
Joined: Mar 25, 2007
Thanks, Keith. I figured out how to handle it, though. I used the object in the wildcarded form: so I took a DeliveryCalendarDay<?> object from the List<DeliveryCalendarDay<?>>. Then I was able to use all the features of the base class, which is fortunately all I needed anyway. I had to change every reference in my code from the specific subclass to this wildcard generic class, but it works, whee!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Using objects returned from a wildcard list