Generic in java integration and generic in java Collection

Source: Internet
Author: User

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;
}

}

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.