Java Generics Tutorial
Selected Reading
- Java Generics - Discussion
- Java Generics - Useful Resources
- Java Generics - Quick Guide
- Java Generics - No Overload
- Java Generics - No Exception
- Java Generics - No Array
- Java Generics - No instanceOf
- Java Generics - No Cast
- Java Generics - No Static field
- Java Generics - No Instance
- Java Generics - No Primitive Types
- Java Generics - Methods Erasure
- Unbounded Types Erasure
- Java Generics - Bound Types Erasure
- Java Generics - Types Erasure
- Generics - Guidelines for Wildcards
- Lower Bounded Wildcards
- Generics - Unbounded Wildcards
- Upper Bounded Wildcards
- Java Generics - Generic Map
- Java Generics - Generic Set
- Java Generics - Generic List
- Java Generics - Multiple Bounds
- Bounded Type Parameters
- Java Generics - Raw Types
- Java Generics - Parameterized Types
- Java Generics - Multiple Type
- Java Generics - Generic Methods
- Java Generics - Type inference
- Type Parameter Naming Conventions
- Java Generics - Generic Classes
- Java Generics - Environment Setup
- Java Generics - Overview
- Java Generics - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Generics - Unbounded Wildcards
Java Generics - Unbounded Wildcards
The question mark (?), represents the wildcard, stands for unknown type in generics. There may be times when any object can be used when a method can be implemented using functionapty provided in the Object class or When the code is independent of the type parameter.
To declare a Unbounded Wildcard parameter, pst the ? only.
Example
Following example illustrates how extends is used to specify an unbounded wildcard.
package com.tutorialspoint; import java.util.Arrays; import java.util.List; pubpc class GenericsTester { pubpc static void printAll(List<?> pst) { for (Object item : pst) System.out.println(item + " "); } pubpc static void main(String args[]) { List<Integer> integerList = Arrays.asList(1, 2, 3); printAll(integerList); List<Double> doubleList = Arrays.asList(1.2, 2.3, 3.5); printAll(doubleList); } }
This will produce the following result −
Output
1 2 3 1.2 2.3 3.5Advertisements