Home > Java > javaTutorial > body text

Methods of predefined Class objects in java

WBOY
Release: 2023-07-01 18:41:14
forward
1425 people have browsed it

    Basic Java types (boolean, byte, char, short, int, long, float and double) and the keyword void are also represented as Class objects through the class attribute;

    Class boolean isPrimitive() in class: Determines whether the specified Class object represents a basic type.

    Static TYPE fields of packaging classes and Void classes;

    Integer.TYPE == int.class ;
    Integer.class == int.class;
    Copy after login

    Class instance objects of array types:

    Class clz = String[].class;
    Copy after login

    How to compare the Class objects of arrays to see if they are equal? ​​Dimensions of arrays and the type of the array;

    isArray() method in the Class class: Determines whether this Class object represents an array type..

    package junereflect624;
    public class PreClassDemo2 {
    public static void main(String[] args) {
    Class> in = int.class;
    System.out.println(in);//int
    Class> in2 = Integer.class;
    //包装类都有一个常量TYPE,用来表示其基本数据类型的字节码
    Class> in3 = Integer.TYPE;
    System.out.println(in2);//class java.lang.Integer
    System.out.println(in3);//int
    System.out.println(in3 == in);//true 包装类都有一个常量TYPE,用来表示其基本数据类型的字节码,所以这里会相等!
    System.out.println(in3 == in2);//false
    Class s = String [].class;
    Class i = int [].class;
    //System.out.println(i ==s);//编译根本就通过不了,一个是int,一个是String
    }
    //这两个自定义的方法是可以的,一个int,一个Integer//包装类与基本数据类型的字节码是不一样的
    public void show(int i){}
    public void show(Integer i){}
    }
    Copy after login

    The above is the detailed content of Methods of predefined Class objects in java. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!