X. Java Generics (ii)

Source: Internet
Author: User

First, the phenomenon of wiping out in the generic type

1. What is the phenomenon of wiping out? See the following example:

Import java.util.ArrayList; 2  3  4 public class Erasetypeequivalence {5 public     static void Main (String[]args) {6         class C1 = n EW arraylist<string>(). GetClass (); 7         Class c2 = new arraylist<integer>(). GetClass (); 8          9         SYSTEM.OUT.PRINTLN (C1 = = }11}    

The results are as follows:

Actually is true, the first point of contact, each object class, will only create a class class of its type in the Java Virtual machine, to create other objects,
Here, though, the generic parameter type is different, but it is essentially a ArrayList class object, so the two are the same. So is true
In this case, there is the so-called generic erase phenomenon.
Inside the generic, no information about the generic parameters can be obtained. That is, although the object is passed in a different time, but after entering into a generic container, their type information is not, and is considered to be "untyped".

X. Java Generics (ii)

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.