[英]What exactly is “.class” in Java Source Code
I was surfing in SO & I found syntax in Java as below: 我在SO中冲浪,并且在Java中发现如下语法:
String.class.getDeclaredField("value");
I could not understand how it works 我不明白它是如何工作的
Example: 例:
In System.out.println();
在
System.out.println();
out
is static variable in System class of PrintWriter out
是PrintWriter的System类中的静态变量
Can any one explain what String.class.getDeclaredField("value");
谁能解释一下
String.class.getDeclaredField("value");
and it's returning object of Field
class means? 它是
Field
类的返回对象的意思?
I just looked & I couldn't find class property(field) in String class. 我只是看了一下,而我在String类中找不到类property(field)。
What is it actually doing? 它实际上在做什么?
Thanks in advance. 提前致谢。
String.class
is a literal that represents the String
class which is of type Class<String>
. String.class
是一个文字,表示类型为Class<String>
的String
类。 getDeclaredField()
is a method defined on the class Class
. getDeclaredField()
是在类Class
上定义的方法。
see also: What is a class literal in Java? 另请参见: Java中的类文字是什么?
The literals are defined in the Java Language Specification 15.8.2 这些文字在Java语言规范15.8.2中定义
查找Java Reflection
API和Class.getDeclaredField()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.