`

Obtaining Annotations at Run Time by Use of Reflection(通过反射获取注释的值

    博客分类:
  • java
阅读更多

 

 

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;

// A simple annotation type.
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
  String stringValue();

  int intValue();
}

public class MainClass {
  // Annotate a method.
  @MyAnnotation(stringValue = "Annotation Example", intValue = 100)
  public static void myMethod() {
  }

  public static void main(String[] a) {
    try {
      MainClass ob = new MainClass();
      Class c = ob.getClass();

      Method m = c.getMethod("myMethod");

      MyAnnotation anno = m.getAnnotation(MyAnnotation.class);

      System.out.println(anno.stringValue() + " " + anno.intValue());
    } catch (NoSuchMethodException exc) {
      System.out.println("Method Not Found.");
    }

  }
}
 
分享到:
评论

相关推荐

    Continuous Deployment of Mobile Software at Facebook

    Continuous Deployment of Mobile Software at Facebook Abstract Continuous deployment is the practice of releasing software updates to production as soon as it is ready, which is receiving increased ...

    WizFlow网页编辑

    effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be ...

    hibernate-shards.jar

    effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be ...

    Vagaa哇嘎画时代--体验群体智慧的力量!

    3.5 You may not through the use of any third party software application, alter or modify the values stored by the Software in your computer's memory, on your computer's hard disk, or in your computer'...

    Two-Level Segregate Fit

    Traditionally, real-time systems run for long periods of time and some (embedded applications), have strong constraints of memory size. Fragmentation can have a significant impact on such systems. It...

    Universal-USB-Installer

    Source Code is made available at time of download, from the official UUI page: http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/ IMPORTANT! No Warranty is being offered with this ...

    雷达技术知识

    Figure displays concept of reflection and refraction of light according to angle of incidence. The intensity of light is greater as the angle of incidence approaches nadir. (Jenkins, F.A., White, RE....

    Analysis of the algebraic side channel attack

    For instance, the study in the case of the Hamming weight model gives that the probability of obtaining at least 64 (resp. 130) linear relations is about 50% for the substitution layer of PRESENT ...

    implementation of SPWM for Inverter

    The design is made by the H-bridge topology with the use of MOSFET as a switch. The simulation for the system constructed with the help of MATLAB/SIMULINK. The SPWM method improves the efficiency and...

    获取当前位置—Obtaining the Current Location.

    在Android平台上获取设备当前位置是一项常见的需求,可以通过LocationManager类实现。LocationManager类是Android系统提供的用于管理位置信息的API。为了获取位置更新,应用需要使用LocationManager的特定方法注册...

    Theory of Active Learning

    learning, where the labeled data are taken at random. The objective in active learning is to produce a highly-accurate classifier, ideally using fewer labels than the number of random labeled data ...

    Learn.Java.for.Android.Development_Apress.2010+src

    The book also briefly presents most (if not all) of Java version 7''s language features, although not much is said about closures or modules (which were not finalized at the time of writing)....

    Obtaining a stack trace in C upon SIGSEGV

    ### 获取 C 语言程序在 SIGSEGV 时的堆栈轨迹 #### 代码实现 本文档介绍了一种在不使用调试器的情况下获取 C 或 C++ 程序崩溃时堆栈轨迹的方法。此方法尤其适用于那些希望在程序崩溃时能够追踪到错误发生位置的...

    从冰山获取淡水 obtaining fresh water from icebergs.docx

    标题中的“从冰山获取淡水”是指利用冰山上的冰雪资源来解决淡水资源短缺的问题。这一概念在过去可能被视为一种不切实际的想法,但在科学家警告人类可能会先耗尽淡水再耗尽食物的情况下,许多国家现在正认真考虑这种...

    Obtaining Absolute Encoder Position on a TMS320C240.pdf

    在IT领域,尤其是在嵌入式系统与数字信号处理(DSP)技术中,了解如何获取绝对编码器位置是一项关键技能。本文将深入探讨标题为“在TMS320C240上获取绝对编码器位置”的应用简报,以及其在工业自动化、机器人技术和...

    domain user password obtaining

    domain user password obtaining

    Animation and Control of Breaking Waves.pdf

    method for obtaining the full 3D breaking wave evolution compared to starting the simulation at an early stage and using solely the 3D Navier-Stokes equations. We present a series of 2D and 3D ...

    PSpice for Circuit Theory and Electronic Devices-Paul Tobin[清晰原版]

    It is aimed primarily at those wishing to get up to speed with this version but will be of use to high school students, undergraduate students, and of course, lecturers. Circuit theorems are applied ...

Global site tag (gtag.js) - Google Analytics