In Java, what does a reference to Class.class do?

前端 未结 4 1789
情书的邮戳
情书的邮戳 2021-01-18 19:44

I\'m building a small Android application, but this is more of a Java question than an android question. Looking through the tutorials there are lines that look like:

<
4条回答
  •  暖寄归人
    2021-01-18 20:10

    In JVM, when a class is loaded, an object of the type Class represents the loaded class in memory. com.abc.MyClass.class is a literal expression that represents the Class object for the class com.abc.MyClass.

    The same Class object can also be obtained by calling myClassReference.getClass() method if you have a reference to an object of the class.

    The Class object can be used to find the information on the structure of the class, access fields, invoke methods and instantiate objects of the class using Java Reflection API.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题