A question mark, or wildcard, is used in generics … Based on the types of the arguments passed to the generic method, the compiler handles each method call appropriately. Generics allow an object or method to operate on various types. In this tutorial, we will learn about Java generics with the help of examples. extends Number> 11. We should only do this if we’re (still) working with JDK version 1.4 or lower. There are three main reasons we use Java generics. Suppose when we want to restrict the types that can be used as type arguments in a parameterized type. Your code is less likely to fail at a later point as it provides type safety making your code less error-prone. Thus, superclass defines an inclusive, upper limit. - List> is the abbreviation for List Copyright © 2012 - 2020 CodeJava.net, all rights reserved. See your article appearing on the GeeksforGeeks main page and help other Geeks. Why Generics? The Java collections framework supports generics to specify the type of objects stored The plain old List: is a heterogeneous mixture or a mixed bag that contains elements of all types, for example Integer, String, Pet, Dog, etc.The List