Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Java Programming/API/java.lang.Class

From Wikibooks, open books for an open world
<Java Programming

TheClass<T> is defined in thejava.lang package.

There is aClass<T> object for each class in your program. TheClass object is loaded from <class-name>.class file once when the object of that type is referenced from the first time. After that it stays in memory. TheClass object is responsible to creat all the object instances that belong to that class.

Every array also belongs to a class that is reflected as aClass object that is shared by all arrays with the same element type and number of dimensions. Theprimitive types (boolean,byte,char,short,int,long,float, anddouble), and the keywordvoid are also represented asClass objects. Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded

Since JDK 1.5 the classjava.lang.Class<T> is generic. It's an interesting example of using genericity for something other than a container/collection class.

For example, the type of String.class is Class<String>, and the type of Serializable.class is Class<Serializable>. This can be used to improve the type safety of your reflection code.

Retrieved from "https://en.wikibooks.org/w/index.php?title=Java_Programming/API/java.lang.Class&oldid=3263665"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp