understanding of T and class and class

Source: Internet
Author: User
Tags arrays

First Look at class, ordinary non-generic class.

Note: class is a Java keyword that is used when declaring a Java class;

Instances of class classes represent Java Application Runtime classes (class ans enum) or interfaces (interface and annotation) (each Java class runtime behaves as a class object in the JVM, which can be passed the class name. Class, Type. GetClass (), Class.forName ("Class name"), and other methods to get the class object). Arrays are also mapped to classes of class objects, and all arrays that have the same element type and number of dimensions share the class object. The base type boolean,byte,char,short,int,long,float,double and the keyword Void are also represented as Class objects.

T Bean;

Class<t> Bean;

Class<?> Bean;

In the use of reflection to obtain properties, encountered such a writing, specifically to look for some information to study a bit.

The individual T represents a type and class<t> and class<?> represent the class for which the type corresponds

Class<t> when instantiating, T should be replaced by a specific class
Class<?> is it a wildcard generic,? can represent any type

<? Extends T> Limited wildcard, which represents an unknown subclass of T.
<? Super T> lower bound wildcard, which represents an unknown parent class for T.

Public T Find (class<t> clazz, int id);
An instance is generated from a class to reflect it, and it is not possible to do so alone with T.

The object class contains a method called GetClass, which allows you to obtain an instance of the type class. A type class refers to a class that represents a type, because everything is an object, and the type is no exception, and in Java the Type class is used to represent a type. All type classes are instances of class classes. GetClass () will see the return class<?>.

In the JDK, the definition of the normal class.newinstance () method returns object, which is to be cast to another type;

However, the Class<t>,class.newinstance () method using generics has a specific return type;

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.