Questions tagged [java-annotations]

211 questions
0
votes
2 answers

Java @FinalArgs annotation - how to?

I am transitioning from Scala to Java and miss having final parameters by default. I explored an experimental version of the Lombok library here (background info here) which had files hinting at this functionality:…
Michael Lafayette
  • 2,972
  • 3
  • 20
  • 54
0
votes
2 answers

Java reflection: annotation not found even if it's present

I'm using reflection for find a method in a class and the get the annotation "PermessiNecessari" that describe the type of the operation (CREATE, DELETE,...) that a method implements. This is a piece of authorization check implementing a picketlink…
Daniele Licitra
  • 1,520
  • 21
  • 45
0
votes
1 answer

Reflect Annotation of an Instance of my own Class

I have several Classes A1,A2,A3 which extend the abstract class myA. These classes have x fields of class B. The fields of class B are annotated with the annotation Test.(Test is available at runtime) How can i get the annotation Test and its value…
LLLen
  • 23
  • 5
0
votes
0 answers

Is it possible to add constraints in Java Custom Annotations to validate that value is specified for any one of the available attributes?

For example, consider the following annotation. Here both value & name attributes are mandatory. @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface TestAnnotation { String value(); String…
0
votes
0 answers

@Transactional annotation on service layer

I have a DAO class where I have 2 methods annotated with the Spring @Transactional annotations, as follows: public class ClassDAO { @Transactional public void save() throws Exception { } @Transactional public void save2() { …
Henry
  • 67
  • 5
0
votes
0 answers

java annotation with argument named default

Is it possible to create an annotation that uses the keyword default as one of the parameters? Something like // Annotation Definition public @interface Optional { Object default() default null; } - // Usage - function declaration public void…
NDavis
  • 1,127
  • 2
  • 14
  • 23
0
votes
2 answers

AbstractProcessor, how to claim for annotations which target is another annotation?

Given this annotation: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface Interceptor { Class value(); } The users of my library can extend its API creating custom annotations…
Víctor Albertos
  • 8,093
  • 5
  • 43
  • 71
0
votes
0 answers

prevent explicit invocation of an overridable method (Java)

I have a number of classes that define a method, and I want to execute some code (say, some "prologue" and "epilogue") around that method: public interface Thing { public void stuff(); public void callStuff(); } public abstract class…
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0
votes
2 answers

Why does "Integer.TYPE" show error in annotation "attribute value must be constant"

I've created an annotation: @Target(ElementType.FIELD ) @Retention( RetentionPolicy.RUNTIME ) public @interface Test { Class something(); } But when I call it with Integer.TYPE (for the return type of an int), it shows the error. public class…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
-1
votes
1 answer

Removal of a block of code during runtime

I need to remove a particular function or a class from my Java code when it is being converted into .jar file using Maven. But the caveat is the function or class should stay inside the source code. Is there any such way in which I can achieve this…
-1
votes
2 answers

Writing custom annotations in java - TimeCounter annotation example

Basically I have a requirement to track time spent in a method using custom annotation. (I know spring AOP can be used for this, but we can not use it in our product). public class TimeCounterDemo { @TimeCounter public void…
joven
  • 371
  • 1
  • 6
  • 17
-1
votes
2 answers

What is the difference between @Deprecated vs @Deprecated()?

Came across this @Deprecated() today. Curious to know @Deprecated vs @Deprecated() but both are resolving to the same interface Deprecated by the compiler. Are they both different or are they same? Is there some practice to use one over another?
Tom Taylor
  • 3,344
  • 2
  • 38
  • 63
-1
votes
2 answers

Why is annotation not retained in class file

If it define the following annotation: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import…
user79074
  • 4,937
  • 5
  • 29
  • 57
-1
votes
1 answer

Function to retrieve the top-most annotation from the call stack

I would like to define an abstract base class that defines generic reusable test cases that I want to implement over and over again when testing various APIs. The idea is to define the tests once, and then I can just inherit from the generic test…
John Arrowwood
  • 2,370
  • 2
  • 21
  • 32
-2
votes
3 answers

How do you know if a class is an annotation

how to juge a class is an annotation, How do you know if a class is an annotation Is there a good Samaritan out there,,,,,,, how to juge a class is an annotation
1 2 3
14
15