Generics in generics and Java

Source: Internet
Author: User

Take notes to tidy up ~ ~ ~

First, the concept of the heap object is drawn.

What is a heap object is an object that the program can create or delete at any time while it is running, either with the new operator (or the malloc function) or the delete operator (or the free function). Generics can be thought of as a class of heap objects.

Generics are a feature of programming languages. Allows programmers to define variable parts when writing code in a strongly typed programming language, which must be specified before they are used.

The various programming languages and their compilers and operating environments have different support for generics. Parameterization of the type to achieve code reuse a data type that improves the productivity of software development.

There are two main types of generics:
1. In program encoding, some types that contain type parameters , that is, generic parameters can only represent classes, cannot represent individual objects. (This is the more common definition of today)

2. Some classes that contain parameters in the program code. Its parameters can represent classes or objects, and so on. (Most people call this a template) regardless of which definition is used, the generic parameter must be specified when the generic is actually used .

Https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/generics/generic-classes This is Microsoft's explanation for generic classes.

It points out that generic classes are most commonly used in collections, such as linked lists, hash tables, stacks, queues, trees, and so on. Operations like adding and removing items from a collection are performed in substantially the same way regardless of the type of data being stored.

Knowing the definition, what are the benefits of using generics? This concludes with a look at generics in Java.

Generics in Java:

Generics in generics and Java

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.