Questions tagged [annotations]

In programming, annotations are used to add information to a code element which cannot be expressed by the type system.

In programming, annotations are used to add information to a code element which cannot be expressed by the type system.

Java annotations

Up to annotations were only usable inside comments and were used for denoting special information like the author of a class or method or references to other entities.

In some cases they were also used for code generation, by facilitating the toolchain.

As these annotations were part of the code, it was not possible to use them in any way at run time since they were not part of the byte code.

With , annotations became a proper part of java syntax. Annotations can be defined using a syntax similar to the definition of interfaces. They can be used to annotate classes, methods, fields, parameters and packages.

Depending on the definition an annotation is available in source code, byte code or run time. Therefore they can be used for code generation, byte code manipulation at class loading time and via reflection at run time.

For info more see Wiki page and docs.oracle.com

C# Attributes

Attributes are a similar concept to Java annotations, they provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time and used in any number of ways.

13026 questions
6
votes
3 answers

Enable Jackson to not output the class name when serializing (using Spring MVC)

Is there a way to force Jackson not to put the class name in the Json output? I asked a question that led to this question, but I'm asking what I hope is a more focused question. I'm using Spring MVC while doing this, but I'm not sure how much that…
AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
6
votes
1 answer

how to convert site minder xml configuration using Spring4 Java config

I am converting an old version based Spring application to annotation based Spring4 application. As a first step I converted all xmls to java configuration based annotations. The application is working fine, but the only issue is with the site…
Alex Man
  • 4,746
  • 17
  • 93
  • 178
6
votes
2 answers

Lint fails the build with Security error "WrongConstant: Incorrect constant". IntDef annotation

In my Result class I annotated with @IntDef first integer parameter in newInstance() method like this: public class Result { public static final int SUCCESS = 0; public static final int FAIL = 1; public static final int UNKNOWN = 2; …
dmitriyzaitsev
  • 716
  • 9
  • 17
6
votes
2 answers

Custom annotation on method argument is not being executed

I have implemented a custom annotation @Password to perform validation on an argument of my method setPassword(). The annotation is defined like this: // Password.java import java.lang.annotation.*; import static…
robguinness
  • 16,266
  • 14
  • 55
  • 65
6
votes
1 answer

Using Fluent-NHibernate with tables in different database schemas

I have a database that I'm running several applications from. I like to separate the tables by creating a schema for each application. For my newest application I'm using FluentNHibernate. Seems like I have most of the plumbing correct but when I…
Eric Neunaber
  • 431
  • 3
  • 10
6
votes
2 answers

java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException when initializing context

I'm getting an exception when starting my project with the mvn exec:java command Trace: 2015-08-11 16:57:58 INFO DatabaseBeansConfig:60 - Creating bean connectionFactory Exception in thread "main" java.lang.NoClassDefFoundError:…
GCarbajosa
  • 236
  • 1
  • 4
  • 13
6
votes
1 answer

Difference between MainThread, UiThread, WorkerThread, BinderThread in Android Annotation

As i read in the android annotations for thread document We have four types of thread, @MainThread @UiThread @WorkerThread @BinderThread What is differences?
AliSh
  • 10,085
  • 5
  • 44
  • 76
6
votes
2 answers

Can I override a PHP trait property in a consumer class in order to use Doctrine2 annotations?

I'm using traits to implement some Taggable behaviour in a Symfony app, using Doctrine2 for persistence, and annotations to configure that. The main annoyance I have is that in the trait, my IDE has no idea of the type of $this->tags, and throws up…
TheHud
  • 347
  • 3
  • 10
6
votes
1 answer

Annotation for all-delete-orphan in hibernate 4.1.4

I'm new to this hibernate annotation. I want to convert this xml mapping into annotations:
6
votes
7 answers

Java design issue where behavior is attached to annotations

Let say I use JPA by using @transactions annotations. So to have any method run under a transaction I add a @transaction annotations and BINGO my method run under a transaction. To achieve the above we need have a interface for the class and the…
Bhuvan
  • 4,028
  • 6
  • 42
  • 84
6
votes
2 answers

How to use FindBugs’ @CheckForNull, @Nonnull and @Nullable annotations correctly

I would like to formally annotate my function signatures to clarify their contracts—especially if null params and return values are permitted or prohibited—in a way that FindBugs’ static code analysis tool (and maybe other) can make use of it. There…
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
6
votes
2 answers

spring-data-mongodb optional query parameter

I am using spring-data-mongodb. I want to query database by passing some optional parameter in my query. I have a domain class. public class Doc { @Id private String id; private String type; private String name; private int…
mahendra kawde
  • 855
  • 4
  • 25
  • 44
6
votes
1 answer

The attribute value is undefined for the annotation type Produces for "MediaType.APPLICATION_JSON"

I am getting a weird warning (while hovering the red line in eclipse) for this very simple restful service code: (Eclipse draws a red line under "MediaType.APPLICATION_JSON") import java.util.List; import java.util.logging.Logger; import…
brainmassage
  • 1,234
  • 7
  • 23
  • 42
6
votes
2 answers

Is there Commons AnnotationUtils like library? (Java)

I can't find a general utilities (static methods) library for querying for annotations other than either using the annotations api directly and writing my own or using Springs: Springs Annotation Utils Normally I would not mind using Springs but…
Adam Gent
  • 47,843
  • 23
  • 153
  • 203
6
votes
1 answer

Get TypeElement from Generic TypeParameterElement for Java Annotation Processor?

Using Java Annotation Processors I have the following type: @NameToken(value={"startPage"}) public interface MyProxy extends Proxy { } and: public interface Proxy { } I have the TypeElement of Proxyas: TypeElement…
Michael
  • 32,527
  • 49
  • 210
  • 370
1 2 3
99
100