Java-13.14 captures the type parameters that are replaced by wildcards from the ground up
In this chapter, we will continue to discuss the topic of wildcards. We will mainly discuss how to capture the type parameters that are replaced by wildcards?
Example:
Package com. ray. ch13; public class Test {public static
Void test (Holder
Holder) {T t = holder. get (); System. out. println (t. getClass (). getSimpleName ();} public static void test2 (Holder holder) {test (holder);} public static void main (String [] args) {test2 (new Holder
(1); test2 (new Holder
(1.0); test2 (new Holder
("1");} class Holder
{Private T item; public Holder (T t) {item = t;} public T get () {return item ;}}
Output:
Integer
Double
String
The preceding example shows the type information of a typical type parameter that is replaced by a capturing wildcard. Note that we need to input an exact type.
Summary: This chapter briefly introduces the type parameters used to capture wildcards, which are rarely used in current programming.
This chapter is here. Thank you.