/*** 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