Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check equality of annotations?

How would you implement this method:

public boolean equal(Annotation a1, Annotation a2) {
   ...
}

Sample input ():

@First(name="1", value="1"), @Second(name="1", value="1")
@First(value="2"),           @First(name="2")
@First(value="3"),           @First(value="3")
@Second(name="4", value="4), @Second(name="4", value="4")

Sample output:

false
false
true
true

As you can see, the expected behavior of equal is clear and similar to expected behavior of standard equals method of regular objects in java (the problem is that we cannot override equals for annotations).

Are there any libs or standard implementations?

like image 909
Roman Avatar asked Jul 26 '11 06:07

Roman


People also ask

How do you check annotations?

The isAnnotation() method is used to check whether a class object is an annotation. The isAnnotation() method has no parameters and returns a boolean value. If the return value is true , then the class object is an annotation. If the return value is false , then the class object is not an annotation.

How does annotate work?

Annotating is any action that deliberately interacts with a text to enhance the reader's understanding of, recall of, and reaction to the text. Sometimes called "close reading," annotating usually involves highlighting or underlining key pieces of text and making notes in the margins of the text.

Does annotation use reflection?

Accessing your annotation via Java reflection. To process your annotation you could write your own annotation processor. Typically you use Java reflection for this. Java reflection allows you to analyze a Java class and use the information contained in this class at runtime.


1 Answers

Doesn't the overriden equals for Annotation work? Maybe I don't understand your question.

like image 98
Petar Minchev Avatar answered Oct 02 '22 01:10

Petar Minchev