Java object-oriented---generics

Source: Internet
Author: User

Concept

Generics solve the security problem of data types by identifying the type of a property in a class or the return value and parameter type of a method at the time the class is declared.

Format

Access Permissions class class name < Generics, generics ... >{

Property

Method

Sample code

Class gnericity<t,g...>{ private T i;  void SetI (T i) { this.i = i;  } Public T Geti () { return i; }}

Creation of objects

Class name < concrete type > Object name = new class name < concrete type > ();

Sample code

New Gnericity<string> ();

wildcard character "? ”

Used when parameters are passed in a method. Class of generics to be used, passed as parameter in the method

Sample code

 Public void wildcard (gericity<?> gericity) {
Method Body}

Generic interface

Sample code

Interface genricity<t>{}

Java object-oriented---generics

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.