JDK1.5 Generics_MySQL

Source: Internet
Author: User
Generics is one of the most important features of JDK and is mainly used to process collections. The following code passes JDK1.5 debugging. Code Example 1: Demo. javapackagemaoxiang. examples. jdk15.generics; importjava. util. ArrayList; importjava. util. Collection; importjava. util. HashMap; importjava JDK

Generics is one of the most important features of JDK 1.5 and is mainly used to process collections.

The following code is successfully debugged in JDK 1.5.

Code Example 1: Demo. java

Package maoxiang. examples. jdk15.generics;
Import java. util. ArrayList;
Import java. util. Collection;
Import java. util. HashMap;
Import java. util. collections list;
Import java. util. List;
Import java. util. Map;

/**
* @ Author Mao Xiang
*
* Demonstrate how to use the Generics feature. The code is from the Generics tutorial:
* Http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
*
* Generics is similar to a template in C ++.
* Differences:
* 1.
* 2.
*/

Public class Demo {
Public static void main (String [] args ){}

/**
* Simplest usage
*/

Public void Test1 (){

// Previous usage
// List myIntList = new writable List (); // 1
// MyIntList. add (new Integer (0); // 2
// Integer x = (Integer) myIntList. iterator (). next (); // 3 needs to be forcibly converted
// Usage 1.5
List MyIntList = new parameter list (); // 1'
MyIntList. add (new Integer (0); // 2'
Integer x = myIntList. iterator (). next (); // 3'
}

/**
* Anonymous character usage
*/

Public void Test2 (){
List List = new ArrayList ();
// Print a set with anonymous characters

Wildcards (list );
Wildcards1 ();
/*
* If Wildcards2 is defined as Wildcards2 (List Shapes)
* The following call errors
*/
Wildcards2 (list );
}

Public void Wildcards (Collection <? > C ){
// Previous usage
// Iterator I = c. iterator ();
// For (int k = 0; k <c. size (); k ++ ){
//
Log (I. next ());
/

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.