Biblioteca Java - Rev 32

Subversion Repositories:
Rev:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package exempleadnotari;

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

/**
 *
 * @author Mihai Hulea mihai.hulea@aut.utcluj.ro
 */

@Owner(
    value = "546",
    name="User",
    age=37,
    newNames={"Alin", "Dan"}
)
public class ExempleAdnotari {

    public static void displayOwnerDetails() throws Exception{
        for (Annotation annotation : ExempleAdnotari.class.getAnnotations()) {
            Class<?> type = annotation.annotationType();
            System.out.println("Values of " + type.getName());

            for (Method method : type.getDeclaredMethods()) {
                System.out.println(" " + method.getName() + ": " +
                                         method.invoke(annotation, null));
            }
        }

    }
   
    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws Exception {
        ExempleAdnotari.displayOwnerDetails();
    }
   
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Owner {
    String   value() default "";
    String   name();
    int      age();
    String[] newNames();
}