"Thinkinginjava" 41, capture conversion

Source: Internet
Author: User

/*** Book: Thinking in Java * Function: Capture conversion * File: captureconversion.java* time: May 19, 2015 07:52:43* Author: cutter_point*/package Lesson15_generices;public class captureconversion{static <T> void F1 (holder<t> Holder) { System.out.println ("This is F1 ()"); t = Holder.get ();//This is the value that gets holder, which is the value of the T type System.out.println (T.getclass (). Getsimplename ()); Get the type name}static void F2 (holder<?> Holder)//Because F1 needs an exact parameter, but the F2 parameter does not appear to be exact, but F2 is called F1, so the parameter type is captured when F2 is called F1 System.out.println ("Here is F2"); F1 (holder);//call f1}public static void Main (string[] args) {Holder raw = new holder< Integer> (1);//The Incoming type is INTEGERF1 (raw);  There is a warning that the F1 is called directly, returning Integerf2 (RAW); This has no warning, return to Holder rawbasic = new Holder (); Rawbasic.set (new Object ());  Warning F1 (rawbasic); F2 (Rawbasic); Holder<?> WC = new Holder<double> (1.0); F2 (WC);}}


Output:

This is F1 ()
Integer
This is F2.
This is F1 ()
Integer
This is F1 ()
Object
This is F2.
This is F1 ()
Object
This is F2.
This is F1 ()
Double




"Thinkinginjava" 41, capture conversion

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.