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?
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.
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.
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.
Doesn't the overriden equals for Annotation
work? Maybe I don't understand your question.
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