Java - Annotation Member String Type

Introduction

The following code contains the code for an annotation type called Name with two elements of the String type.

@interface Name { 
    String first(); 
    String last(); 
} 
  

The following code shows how to use the Name annotation type in a program:

  
@Name(first="Tom", last="James") 
class NameTest { 
        @Name(first="Mary", last="Edith") 
        public void aMethod() { 
        } 
} 

You can use the string concatenation operator (+) in the value expression for an element of a String type.

@Name(first="A" + "B", last="C" + "D") 

Demo

@interface Name { 
    String first(); //from w  w w.  j  a  v a2  s.  c  o m
    String last(); 
} 
@Name(first="A" + "B", last="C" + "D") 
class A{

}

Quiz