永发信息网

java 问题 @interface :

答案:2  悬赏:10  手机版
解决时间 2021-01-03 04:19
  • 提问者网友:贪了杯
  • 2021-01-03 00:17
public @interface Column {
String value() default "";
}
这段代码是什么意思?@interface 与interface 的区别是什么?
最佳答案
  • 五星知识达人网友:山河有幸埋战骨
  • 2021-01-03 01:30
@interface 是定义注解
全部回答
  • 1楼网友:有你哪都是故乡
  • 2021-01-03 02:34
import java.lang.annotation.elementtype; import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy; import java.lang.annotation.target; @target({elementtype.method,elementtype.field,elementtype.type}) //用于表示hxqannotation可以标示在什么地方 @retention(retentionpolicy.runtime) //用于表示可以存活到什么时候 @interface myanno {          string value(); }; @myanno(value="这里可以赋值哦") public class annotationtest {     public string str;     private void init() {         // 在使用annotation的类中利用反射操作得到annotation         // 如果该注解存在,则使用反射得到并打印         myanno ann=this.getclass().getannotation(myanno.class);         str=ann.value();     }     public annotationtest() {         init();     }     public static void main(string[] args) {     system.out.println(new annotationtest().str);     } } 写了一个简单的例子 给你做参考  ssh里面用的很多 给属性注入值啊 初始化啊  还有切面编程的时候也会大量用到
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯