Home > Back-end >  Wildcard capture exactly what is the use? Since there is a why use swap to call swapHelper swapHelpe
Wildcard capture exactly what is the use? Since there is a why use swap to call swapHelper swapHelpe

Time:09-29

Feeling "Java core technology volume I" this place is a bit confused,
 
Public static void swap (Pair<?> P) {

SwapHelper (p);
}
Public static & lt; T> Void swapHelper (Pair P) {

T T=p.g etFirst ();

P. etFirst (p.g etSecond ());

P. etSecond (t);

}

P - 335, said the inevitable
 
A public static void maxminBonus (Manager [], Pair<? Super Manager> Resu1t) {

MaxminBonus (a, result);

PairAlg. Swap (result);//OK - swapHelper captures wildcard type

}

Turning the program list becomes
 
A public static void maxminBonus (Manager [], Pair<? Super Manager> Resu1t) {

MaxminBonus (a, result);

PairAlg. SwapHelper (result);//OK - swapHelper captures wildcard type

}
  • Related