Java examples for java.lang.annotation:Annotation Attribute
find Named inject Annotation
/******************************************************************************* * Copyright (c) 2014 Red Hat, Inc../* w w w . ja va2 s . c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import javax.inject.Named; public class Main{ public static void main(String[] argv) throws Exception{ Class cls = String.class; System.out.println(findNamed(cls)); } public static String findNamed(final Class<?> cls) { final Named annotation = cls.getAnnotation(Named.class); return annotation == null ? null : annotation.value(); } public static String findNamed(final Object obj) { return findNamed(obj.getClass()); } }