Tutorial by Examples: annotation

The Standard Edition of Java comes with some annotations predefined. You do not need to define them by yourself and you can use them immediately. They allow the compiler to enable some fundamental checking of methods, classes and code. @Override This annotation applies to a method and says that th...
Java's Reflection API allows the programmer to perform various checks and operations on class fields, methods and annotations during runtime. However, in order for an annotation to be at all visible at runtime, the RetentionPolicy must be changed to RUNTIME, as demonstrated in the example below: @i...
Annotation types are defined with @interface. Parameters are defined similar to methods of a regular interface. @interface MyAnnotation { String param1(); boolean param2(); int[] param3(); // array parameter } Default values @interface MyAnnotation { String param1() defau...
Documentation comments are placed directly above the method or class they describe. They begin with three forward slashes ///, and allow meta information to be stored via XML. /// <summary> /// Bar method description /// </summary> public void Bar() { } Information in...
The class we are going to test is: public class Service{ private Collaborator collaborator; public Service(Collaborator collaborator){ this.collaborator = collaborator; } public String performService(String input){ return collaborator.transformS...
Equivalently, we can use the $inject property annotation to achieve the same as above: var MyController = function($scope) { // ... } MyController.$inject = ['$scope']; myModule.controller('MyController', MyController);
For annotating some point of interest on map, we use pin annotation. Now, start by creating annotation object first. MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc] init]; Now provide coordinate to pointAnnotation,as CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake...
You can fetch the current properties of the Annotation by using Reflection to fetch the Method or Field or Class which has an Annotation applied to it, and then fetching the desired properties. @Retention(RetentionPolicy.RUNTIME) @interface MyAnnotation { String key() default "foo";...
The routing configuration is included in your app/config/config.yml file, by default the app/config/routing.yml file. From there you can link to the controllers that have annotated routing configuration: # app/config/routing.yml app: resource: "@AppBundle/Controller" type: ...
The @ContentView annotation can be used to further alleviate development of activities and replace the setContentView statement : @ContentView(R.layout.myactivity_layout) public class MyActivity extends RoboActivity { @InjectView(R.id.text1) TextView textView; @Override protected ...
You can inject any type of resource, Strings, Animations, Drawables, etc. To inject your first resource into an activity, you'll need to: Inherit from RoboActivity Annotate your resources with @InjectResource Example @InjectResource(R.string.app_name) String name; @InjectResource(R.drawa...
You can inject any view using the @InjectView annotation: You'll need to: Inherit from RoboActivity Set your content view Annotate your views with @InjectView Example @InjectView(R.id.textView1) TextView textView1; @InjectView(R.id.textView2) TextView textView2; @InjectView(R.id.imag...
Until Java 8, two instances of the same annotation could not be applied to a single element. The standard workaround was to use a container annotation holding an array of some other annotation: // Author.java @Retention(RetentionPolicy.RUNTIME) public @interface Author { String value(); } ...
By default class annotations do not apply to types extending them. This can be changed by adding the @Inherited annotation to the annotation definition Example Consider the following 2 Annotations: @Inherited @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Inher...
This sample annotation indicates that the following method is deprecated. @deprecated def anUnusedLegacyMethod(someArg: Any) = { ... } This can also be equivalently written as: @deprecated def anUnusedLegacyMethod(someArg: Any) = { ... }
This simple macro annotation outputs the annotated item as-is. import scala.annotation.{compileTimeOnly, StaticAnnotation} import scala.reflect.macros.whitebox.Context @compileTimeOnly("enable macro paradise to expand macro annotations") class noop extends StaticAnnotation { def m...
Declaration annotations should be put on a separate line from the declaration being annotated. @SuppressWarnings("unchecked") public T[] toArray(T[] typeHolder) { ... } However, few or short annotations annotating a single-line method may be put on the same line as the method if...
Interface: public interface FooService { public int doSomething(); } Class: @Service public class FooServiceImpl implements FooService { @Override public int doSomething() { //Do some stuff here return 0; } } It should be noted that a class must imple...
The MAF file format is a tab-delimited text file format intended for describing somatic DNA mutations detected in sequencing results, and is distinct from the Multiple Alignment Format file type, which is intended for representing aligned nucleotide sequences. Column headers and ordering may someti...
AppBundle/Entity/Person.php <?php namespace AppBundle\Entity; use DoctrineORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * @ORM\Entity * @ORM\Table(name="persons") * @ORM\Entity(repositoryClass="AppBundle\Entity\PersonRe...

Page 1 of 3