Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Utility of the method 'java.lang.reflect.Method.getDefaultValue()'?

Which is the objective of the method getDefaultValue() in class java.lang.reflect.Method ?, can someone point me out a situation where this method is useful ?.

The description from the API of Method does not say a lot to me, I do not get what is the "annotation member represented by this Method instance" :

Returns the default value for the annotation member represented by this Method instance. If the member is of a primitive type, an instance of the corresponding wrapper type is returned. Returns null if no default is associated with the member, or if the method instance does not represent a declared member of an annotation type.

like image 243
Sergio Avatar asked Sep 14 '12 20:09

Sergio


People also ask

What is Java Lang reflect method?

The reflected method may be a class method or an instance method (including an abstract method). A Method permits widening conversions to occur when matching the actual parameters to invoke with the underlying method's formal parameters, but it throws an IllegalArgumentException if a narrowing conversion would occur.

What is reflected method?

What is reflective practice? Reflective practices are methods and techniques that help individuals and groups reflect on their experiences and actions in order to engage in a process of continuous learning.

What is a method in Java?

A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions.

What is method object in Java?

Java Object is the superclass for all the classes in Java. All the methods of Object class can be used by all the subclasses and arrays. The Object class provides different methods to perform different operations on objects.


1 Answers

Annotations have their "attributes" as methods. For instance:

public @interface Example {
    public String stringValue() default "string default value";
    public int intValue() default 10;
}

The getDefaultValue() of a Method from an annotation returns the default value of an annotation "attribute" defined this way. In the example, the default value of the Method stringValue() is "string default value".

like image 87
Gilberto Torrezan Avatar answered Oct 30 '22 09:10

Gilberto Torrezan