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
5 answers

Need an automatic image tagging API, any suggestions?

I'm building an application which needs to take an image and infer tags related to it. Those tags can be about things, adjectives or even emotions related to the picture. I've already found ALIPR. But I tested it, some other people tested it also…
fjsj
  • 10,995
  • 11
  • 41
  • 57
6
votes
1 answer

Android Annotations - Injecting a list of superclass type

I am trying to achieve the following Spring code using Android Annotations: @Autowired public initHandlerList(List handlerList) { // Do stuff with the list ... } I tried using both an interface and a class. Bean…
Nom1fan
  • 846
  • 2
  • 11
  • 27
6
votes
4 answers

generate annotated doctrine2 entites from db schema

Is it possible to generate Doctrine 2 entities, with the relevant docblock annotations, from an existing database schema?
waigani
  • 3,570
  • 5
  • 46
  • 71
6
votes
1 answer

How to style annotation lines in Google Charts?

I am using Google Charts API to display a vertical line on a LineChart (at a specific point) using annotations. Is it possible to style the annotation line, to make it more visible (change its color/thickness, in case I add some vertical gridlines…
Ralu Bur
  • 165
  • 1
  • 7
6
votes
3 answers

Jackson @JsonProperty not working if property name not equal field name

I have following JSON { "known-name": "Zevs", "approximate-age": 320 } And binding class public class GodBinding { @JsonProperty("known-name") public String name; @JsonProperty("approximate-age") public int age; // constructors …
cane
  • 892
  • 1
  • 10
  • 16
6
votes
3 answers

Loading application context via annotation in benchmark

Let's assume I want to write a benchmark for the class which can be autowired thus I need to load application context. My test has annotation @org.openjdk.jmh.annotations.State(Scope.Benchmark) and main method public static void main(String[] args)…
Rufi
  • 2,529
  • 1
  • 20
  • 41
6
votes
0 answers

Multiple scala macro annotation does not generate class file

I am creating annotations in Scala that create a companion class (if it does not exist yet) and put some methods in the companion class. It works fine when I have one annotation, but when I put two annotations on the class, the class file for the…
Heino
  • 69
  • 5
6
votes
0 answers

Android Studio incorrectly flagging arguments annotated with Snackbar.Duration

Background I wrote a wrapper around a default Snackbar.make method to apply custom styling to my Snackbar instances. The method signature of my custom wrapper is as follows: public static Snackbar makeCustom( @NonNull View view, …
stkent
  • 19,772
  • 14
  • 85
  • 111
6
votes
11 answers

creating unit tests (semi-)automatically?

Is there a framework that supports generating some standard unit tests from annotations? An example of what I have in mind would be: @HasPublicDefaultConstructor public class Foo { } This would obviously be used to automatically generate a unit…
Kim Stebel
  • 41,826
  • 12
  • 125
  • 142
6
votes
2 answers

Hibernate validator change locale at runtime

I made an application with hibernate and use annotations to do the validation. I realized that to translate the message into my language I have to put in the resources folder a file called ValidationMessage_xx.properties. The problem is that what…
ciro
  • 771
  • 1
  • 8
  • 30
6
votes
1 answer

PhpStorm property annotation for instance of class

I know I can use PhpStorm annotations like this: /** * Class Model * @property string name */ class Model {}; $modelInstance = new Model(); $modelInstance->name; When I type $modelInstance-> PhpStorm will offer me "name" in autocomplete. Is it…
Michal
  • 4,952
  • 8
  • 30
  • 63
6
votes
1 answer

Is there anyway to tell compiler to keep variable names around via annotations?

It is very annoying to have the whole app add an @Param() annotation with the variable name for each variable name. It is also frustrating when you change the variable name and have to change the name inside @Param Is there any good way to annotate…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
6
votes
8 answers

How did Java programmers survive before annotations?

Before the introduction of annotations in Java, how was the same functionality achieved? Such a huge portion of what I do every day in Java involves annotations that I can't imagine what it would be like to program without them. What would be an…
Dieter Gantz
  • 195
  • 2
  • 3
  • 7
6
votes
0 answers

How to get the compile-time classpath from an AnnotationProcessor?

I am trying to read the compile time classpath inside an AnnotationProcessor, but I cannot find out how. My annotation processor needs to save the classpath of a build to file, so it can be used when analyzing this build by a third party library…
jactor-rises
  • 2,395
  • 2
  • 22
  • 44
6
votes
2 answers

How to compare dates in validation?

I'm trying to compare dates in my validation. The documentation says it's possible but It's not documented. I'm using annotations and I want one date to be later that the other. How do I do this?
SnelleJelle
  • 933
  • 5
  • 18
  • 35