Reputation: 11
I have a method
public Response xyz ( JAXBElement<T> request ) {
......
}
two different places it is getting called with different JAXBElement.
One with xyz(JAXBElement<a>)
and other with xyz(JAXBElement<B>)
How can I make my method intake generic so that it works with both the methods?
Upvotes: 1
Views: 226
Reputation: 43709
Please try:
xyz(JAXBElement<?> myElement);
Please see this tutorial on generics:
So what is the supertype of all kinds of collections? It's written
Collection<?>
(pronounced "collection of unknown"), that is, a collection whose element type matches anything. It's called a wildcard type for obvious reasons. We can write:void printCollection(Collection<?> c) { for (Object e : c) { System.out.println(e); } }
and now, we can call it with any type of collection.
Upvotes: 2