What is Class Descriptor?
Is it a Class
object of a particular class?
“Descriptors” are objects that describe some attribute of an object. They are found in the dictionary of type objects.
A MethodDescriptor describes a particular method that a Java Bean supports for external access from other components.
Descriptors are Python objects that implement a method of the descriptor protocol, which gives you the ability to create objects that have special behavior when they're accessed as attributes of other objects.
The __set__() method is invoked when the value is set to the attribute, and unlike the __get__() method, it returns nothing. It has two arguments apart from the descriptor object itself, i.e., the instance which is the same as the __get__() method and the value argument, which is the value you assign to the attribute.
Yes, a Class
object is a class descriptor for a certain "class".
From the API:
Instances of this class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as
Class
objects.
Here's an example of a simple usage of Class
methods to reflectively describe types:
static void describe(Class<?> clazz, String pad, String leadin) {
if (clazz == null) return;
String type =
clazz.isInterface() ? "interface" :
clazz.isArray() ? "array" :
clazz.isPrimitive() ? "primitive" :
clazz.isEnum() ? "enum" :
"class";
System.out.printf("%s%s%s %s ( %s )%n",
pad, leadin, type, clazz.getSimpleName(), clazz.getName());
for (Class<?> interfaze : clazz.getInterfaces()) {
describe(interfaze, pad + " ", "implements ");
}
describe(clazz.getComponentType(), pad + " ", "elements are ");
describe(clazz.getSuperclass(), pad + " ", "extends ");
}
static void describe(Class<?> clazz) {
describe(clazz, "", "");
System.out.println();
}
public static void main(String[] args) {
describe(boolean[][].class);
describe(java.math.RoundingMode.class);
describe(java.util.ArrayList.class);
describe(void.class);
}
The above snippet produces the following output:
array boolean[][] ( [[Z )
implements interface Cloneable ( java.lang.Cloneable )
implements interface Serializable ( java.io.Serializable )
elements are array boolean[] ( [Z )
implements interface Cloneable ( java.lang.Cloneable )
implements interface Serializable ( java.io.Serializable )
elements are primitive boolean ( boolean )
extends class Object ( java.lang.Object )
extends class Object ( java.lang.Object )
enum RoundingMode ( java.math.RoundingMode )
extends class Enum ( java.lang.Enum )
implements interface Comparable ( java.lang.Comparable )
implements interface Serializable ( java.io.Serializable )
extends class Object ( java.lang.Object )
class ArrayList ( java.util.ArrayList )
implements interface List ( java.util.List )
implements interface Collection ( java.util.Collection )
implements interface Iterable ( java.lang.Iterable )
implements interface RandomAccess ( java.util.RandomAccess )
implements interface Cloneable ( java.lang.Cloneable )
implements interface Serializable ( java.io.Serializable )
extends class AbstractList ( java.util.AbstractList )
implements interface List ( java.util.List )
implements interface Collection ( java.util.Collection )
implements interface Iterable ( java.lang.Iterable )
extends class AbstractCollection ( java.util.AbstractCollection )
implements interface Collection ( java.util.Collection )
implements interface Iterable ( java.lang.Iterable )
extends class Object ( java.lang.Object )
primitive void ( void )
Class.getName()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With