Java-13.14 captures the type parameters that are replaced by wildcards from the ground up

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.