Questions tagged [java-annotations]

211 questions
2
votes
0 answers

Use SpEL in custom annotation

I have a simple custom annotation: @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Service public @interface SampleDefinition { String description(); String orderNr() default ""; } I need to make a description()…
Adam
  • 884
  • 7
  • 29
2
votes
2 answers

Have a common base type for all my custom annotations

So, I have created several custom annotations: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Foo { } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Bar { } Those annotations…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
2
votes
1 answer

Check return type of ExecutableElement is subtype of Collection

I have an ExecutableElement representing a getter, an example is the one below. public List getStrings(); The only method that allows me to get the details of the return type is ExecutableElement.getReturnType(). It gives me back a…
Phuong Hoang
  • 461
  • 1
  • 6
  • 12
2
votes
1 answer

Using Multiple Custom Annotations for the same property ApiImplicitParams

I have two custom annotations which need to be created to be added on controller endpoints both have the same property @ApiImplicitParams swagger annotation. For many endpoints i need to use ApiImplicitParams from both annotations but in this case…
Jayesh Mulwani
  • 655
  • 6
  • 19
2
votes
1 answer

default annotation for method of an interface

I have an interface: public interface PermissionCallback { @SuppressLint("MissingPermission") void grantedPermission(String permission); void deniedPermission(String permission); } and I want when I implement it, by default add…
beigirad
  • 4,986
  • 2
  • 29
  • 52
2
votes
1 answer

@PostConstruct and unchecked Exceptions

I'm having a difficult time wrapping my head around the Javadoc for @PostConstruct. It says: If the method throws an unchecked exception the class MUST NOT be put into service except in the case of EJBs where the EJB can handle exceptions and…
2
votes
2 answers

Why annotation default String is not identical although they must be constants

I have a rough idea, but still would like to ask if anyone knows why String constants provided as annotation defaults change identity even though they reference static constants. To illustrate, why does this code prints true, true, false,…
SGal
  • 1,072
  • 12
  • 13
2
votes
0 answers

Annotation processor: Is there any way to know if annotated class extends a specific class?

I want to check if any of annotated classes' ancestors is actually android.support.v4.app.Fragment. Currently I wrote a recursive method to do that. I wonder if any better way of doing this? The main purpose is to restrain my annotation to be added…
Arst
  • 3,098
  • 1
  • 35
  • 42
2
votes
1 answer

Java Annotation - Restrict cardinality (occurrance) of annotation with same field element value

I have below condition, which needs Java annotation with a specific field value to appear exactly once in any field of the class. Is it possible with Java 8? My annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) //can use with…
Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
2
votes
0 answers

Errorprone - Disable Checks in ViewBinding classes generated by ButterKnife

In our project we've just started using Google's Errorprone (http://errorprone.info/) to get additional checks during compile time. I've managed to eradicate all remaining warnings we had in our project, but am Stuck with a warning generated within…
florianbaethge
  • 2,520
  • 3
  • 22
  • 29
2
votes
2 answers

Is Java automatically caching annotations and class metadata?

Java has a native support for annotations. I'm wondering if when I call obj.getAnnotation(Test.class), java stores class metadata in any kind of cache. I have the same question with reflection like: for (Method method : obj.getDeclaredMethods()) { …
Serginho
  • 7,291
  • 2
  • 27
  • 52
2
votes
1 answer

Java annotation: using a field value into another field

I have the following annotation class public @interface Size { int min() default 1; int max() default 100; String message() default "Age between min - max"; } Here at the default message() I want the default value of min() and max(). Simply…
Erfan Ahmed
  • 1,536
  • 4
  • 19
  • 34
2
votes
1 answer

Java "Resource Leak" Warning Not Triggering When it Should

I have a class called JavaShellStream that extends the interfaces Closeable and Autocloseable. However, when I use the class, and do not call its close() method, no warning is triggered that there is a resource leak. I have another class called…
Mat Jones
  • 936
  • 1
  • 10
  • 27
2
votes
1 answer

Picketlink custom relationship duplicate record on DB

I'have builded a custom relationship to allow Account to open a Module. So i copied org.picketlink.idm.model.basic.Grant and renamed it. The relationship is created successfully, the database tables are created, but when the relationship is stored…
Daniele Licitra
  • 1,520
  • 21
  • 45
2
votes
1 answer

How to annotate java package and reflect metadata

I would like to annotite java package using simple annotation: @Target(ElementType.PACKAGE) public @interface Related { int apiVersion() default 0; } However when I try to add it to any package I've got compilation error Error:(1, 14) java:…