Generic in java integration and generic in java Collection
Import java. util. ArrayList;
/*
* Generic: New Features of java jdk1.5.
* Benefits of generics:
* 1. Run the error in advance to compile.
* 2. Avoid unnecessary forced type conversion.
*
* Custom method generic: a custom generic is a placeholder for a data type or a data type variable. Generally, T type or E element is used as the placeholder symbol.
* Placeholder symbols can be written at will and must comply with the naming rules of identifiers.
* Method Generic Format:
* <Placeholder> T: defines a generic
*
* If you pass in the basic data type, you can use its packaging class to receive the received data.
* Int ----> Integer;
* Short ---> Short
* Double ---> Double
* Float ----> Float
* Byte ----> Byte
* Boolean ---> Boolean
* Long ---> Long
* Char ---> Charactor
*
*
*/
Public class Demo2 {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
// Requirement: converts the elements in a set to uppercase in lowercase.
/* ArrayList <String> list = new ArrayList <String> (); // <String> generic: determines that only one type of data objects can be stored in the set.
List. add ("aa ");
List. add ("bb ");
List. add ("cc ");
List. add ("dd ");
// List. add (123); // the error message is displayed during running.
For (int I = 0; I <list. size (); I ++ ){
System. out. println (list. get (I). toUpperCase ());
}*/
String s = test ("abc ");
Integer I = test (1, 123 );
}
Public static <abc> abc test (abc s ){
Return s;
}
}