SlideShare a Scribd company logo
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;
/**
* write a program to create a single-value annotation that stores only one value and
* retrieve it during runtime by the JVM
*
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface MySingle{
int value();
}
class MyClass{
@MySingle(value = 100)
public void myMethod(){
System.out.println("Hello");
}
}
public class Demo {
public static void main(String[] args) throws NoSuchMethodException,
SecurityException {
MyClass obj = new MyClass();
Method m = obj.getClass().getMethod("myMethod");
MySingle anno = m.getAnnotation(MySingle.class);
System.out.println("Value = "+anno.value());
}
}
output :
Value = 100

More Related Content

PPTX
Method overloading
DOCX
Scrollable Test App
DOCX
Cursor Demo App
PPTX
Jba7041 sk desa temu jodoh
PPTX
Gif and images
PPT
School Management System Level One
PPT
שילוב מגזרים בתעשייה
PDF
Urlauber starten mit BestFewo ins neue Jahr
Method overloading
Scrollable Test App
Cursor Demo App
Jba7041 sk desa temu jodoh
Gif and images
School Management System Level One
שילוב מגזרים בתעשייה
Urlauber starten mit BestFewo ins neue Jahr

Viewers also liked (12)

PDF
EU: Tractors - Market Report. Analysis And Forecast To 2020
PDF
54e613aa2017a809d8000007
PDF
Resume Manish Mohanan
PPTX
Educacion a distancia
PPTX
154884880 desastres-en-accidentes (1)
PPTX
Maxwell niswonger
PPTX
How Midjournal Use Clojure?
PDF
05 rs4 c 2013 longitudsegura ramaautopista e&s izq
PDF
Kevin_McAlpine_Resume
PDF
2015年11月21日 Unity Asset Touch and Tryアセット一覧
PPTX
Primeros auxilios ( heridas y evacuacion de ptes)
EU: Tractors - Market Report. Analysis And Forecast To 2020
54e613aa2017a809d8000007
Resume Manish Mohanan
Educacion a distancia
154884880 desastres-en-accidentes (1)
Maxwell niswonger
How Midjournal Use Clojure?
05 rs4 c 2013 longitudsegura ramaautopista e&s izq
Kevin_McAlpine_Resume
2015年11月21日 Unity Asset Touch and Tryアセット一覧
Primeros auxilios ( heridas y evacuacion de ptes)
Ad

Similar to single-value annotation (20)

PPT
比XML更好用的Java Annotation
PPT
Unit testing with mock libs
PDF
Wicket 6
PPTX
Awt components
PDF
Web UI test automation instruments
ODP
Bring the fun back to java
PPT
PPTX
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
PDF
Java custom annotations example
PPTX
Androidaop 170105090257
DOCX
Diifeerences In C#
PDF
JDK Power Tools
PDF
Daggerate your code - Write your own annotation processor
PDF
Quick Intro to Android Development
PDF
Workshop 23: ReactJS, React & Redux testing
PDF
So how do I test my Sling application?
DOCX
Advance Java Programs skeleton
PPTX
Java For beginners and CSIT and IT students
PDF
Alexey Buzdin "Maslow's Pyramid of Android Testing"
PDF
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
比XML更好用的Java Annotation
Unit testing with mock libs
Wicket 6
Awt components
Web UI test automation instruments
Bring the fun back to java
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Java custom annotations example
Androidaop 170105090257
Diifeerences In C#
JDK Power Tools
Daggerate your code - Write your own annotation processor
Quick Intro to Android Development
Workshop 23: ReactJS, React & Redux testing
So how do I test my Sling application?
Advance Java Programs skeleton
Java For beginners and CSIT and IT students
Alexey Buzdin "Maslow's Pyramid of Android Testing"
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
Ad

Recently uploaded (20)

PDF
Nekopoi APK 2025 free lastest update
PDF
System and Network Administration Chapter 2
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
top salesforce developer skills in 2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Nekopoi APK 2025 free lastest update
System and Network Administration Chapter 2
Designing Intelligence for the Shop Floor.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Computer Software and OS of computer science of grade 11.pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
L1 - Introduction to python Backend.pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Digital Systems & Binary Numbers (comprehensive )
Design an Analysis of Algorithms I-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 41
top salesforce developer skills in 2025.pdf
medical staffing services at VALiNTRY
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)

single-value annotation

  • 1. 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; /** * write a program to create a single-value annotation that stores only one value and * retrieve it during runtime by the JVM * * */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface MySingle{ int value(); } class MyClass{ @MySingle(value = 100) public void myMethod(){ System.out.println("Hello"); } } public class Demo { public static void main(String[] args) throws NoSuchMethodException, SecurityException { MyClass obj = new MyClass(); Method m = obj.getClass().getMethod("myMethod"); MySingle anno = m.getAnnotation(MySingle.class); System.out.println("Value = "+anno.value()); } } output : Value = 100