问题描述
我不太明白 class
关键字在某些情况下是如何工作的。
I don't really understand how the class
keywords work in some instances.
get(ClientResponse.class)
方法接受 ClientResponse.class
。当它获取它时如何使用它,和只是传递一个实例的优点是什么?
For example, the get(ClientResponse.class)
method takes the ClientResponse.class
. How does it use this when it gets it, and what are the advantages over just passing an instance of it?
推荐答案
SomeClass.class
返回Java类对象。类是泛化的,因此SomeClass.class的实际类型将为 Class< SomeType>
。
returns a Java Class object. Class is genericized, so the actual type of SomeClass.class will be Class<SomeType>
.
此对象的用途,您可以在这里阅读Javadoc:
There are lots of uses for this object, and you can read the Javadoc for it here: http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html
这篇关于在Java中使用class关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!