Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.ref;
- 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;
- public class TestIntRange {
- public static void main(String... str) throws Exception {
- setInt(2);
- setInt(5);
- }
- @IntRange(value1 = 1, value2 = 2, value3 = 3)
- public static void setInt(int a) throws Exception {
- Method method = TestIntRange.class.getMethod("setInt", int.class);
- IntRange intRange = method.getAnnotation(IntRange.class);
- if (intRange.value1() == a || intRange.value2() == a || intRange.value3() == a) {
- System.out.println("Число подходит " + a);
- } else {
- System.out.println("Число не подходит " + a);
- }
- }
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- @interface IntRange {
- int value1();
- int value2();
- int value3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement