Anotation与工厂设计模式
import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class Factory { } @Retention(RetentionPolicy.RUNTIME) @interface MyAnotation{ public String name(); public int age(); } @MyAnotation(name="smith",age = 19) class Emp{ public static void main(String[] args) { MyAnotation myAnotation = Emp.class.getAnnotation(MyAnotation.class); System.out.println(myAnotation.name()); System.out.println(myAnotation.age()); } }
jiapengchu
posted on 2022-03-29 11:46 jiapengchu 阅读(55) 评论(0) 编辑 收藏 举报