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  ww. j  ava 2  s.com*/
    String last(); 
} 
@Name(first="A" + "B", last="C" + "D") 
class A{

}

Quiz