(Not So) Stupid Questions 16: What's the Difference Between Wildcard Generics and no Generics? Blog

    Editor's note: Sometimes the most interesting discussions begin when someone says, "This may be a stupid question, but ...." If the person asking the question has taken the time to think about the problem before asking, the question is often not stupid at all. The uncertainty points out an ambiguity in the specs, holes in the docs, or a search for how more experienced programmers might address a particular problem. From time to time, we will print one of the "(Not So) Stupid Questions" we receive and invite our readers to answer the question in the feedback section.

    Remember that new people are joining the Java community all the time and may be looking for help from those with more experience. Also, those who began with Java as their first language can benefit from those coming to the community with experience in other languages. As always, answer the questions with kindness. You are also welcome to submit your questions to

    This may be a stupid question, but ... "What is the difference between specifying a wildcard for a genericized type and not using the generic notation at all?"

    First thoughts:

    Take this for example:

    interface Example {
      public List<?> getList();
    class ExampleImpl implements Example {
      public List getList() { return new ArrayList(); } // warning: needs unchecked conversion to conform to List<?>

    ExampleImpl  successfully implements Example, but the compiler warns me about the conversion of List to List<?>. I don't see how it's even possible to return a List from the method in ExampleImpl that is not conformable List<?>--if that's truly the case, why does the compiler even warn me at all?

    It makes me wonder what the benefit is for specifying wildcard generic types for an API.  If I were to rewrite the interface's method to return a plain old List, then I wouldn't receive any warnings.

    So I don't get it:

    What's the point of specifying a wildcard for a genericized type, when you can just omit the generics altogether?