<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/java-annotation-summary-html/</link>
<title><![CDATA[java注解Annation的小结]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Sat, 23 Oct 2010 15:38:00 +0000</pubDate> 
<guid>https://www.heckjj.com/java-annotation-summary-html/</guid> 
<description>
<![CDATA[ 
	<span style="font-family: 微软雅黑;">1、从jdk1.5以后就开始出现注解了，主要有@override @depredate @supressWarning <br/><br/>2、怎么样生成一个注解呢？ <br/>&nbsp;&nbsp;注解个普通的接口一样，多的就是仅仅是多添加了一个@,类似 <br/>&nbsp;&nbsp;public @interface Test&#123; <br/>&nbsp;&nbsp;&nbsp;&nbsp;public void value() default &quot;this is&nbsp;&nbsp;frist annation&quot;; <br/>&#125; <br/>注意：注解里面可以由方法组成也可以有枚举组成等！ <br/><br/>3、注解可以声明在类上面，也可以声明在方法上面，当然也可以声明在属性上面，可以通过@targer来表示 <br/>&nbsp;&nbsp; @targer(ElementType.Construct)//在构造器上面进行声明 <br/>&nbsp;&nbsp;&nbsp;&nbsp;ElementType.Field&nbsp;&nbsp;&nbsp;&nbsp; //在属性上面进行声明 <br/>&nbsp;&nbsp;&nbsp;&nbsp;ElementType.Method//在方法上面进行声明 <br/>&nbsp;&nbsp;&nbsp;&nbsp;ElementType.Type&nbsp;&nbsp;//在类上面进行声明&nbsp;&nbsp;</span><span style="font-family: 微软雅黑;"><br/><br/>4、注解也有声明周期，可以在编译的时候有效，也可以在jvm中有效，当然也可以在class文件中有效，主要通过 <br/>@Retention 来表示&nbsp;&nbsp;<br/>RetentionPolicy.Source&nbsp;&nbsp;//注解将被编译器放弃， <br/>RetentionPolicy.CLASS&nbsp;&nbsp;//注解被虚拟机放弃 <br/>RetentionPolicy.RUNTIME //注解即保存在jvm也保存在class文件等 <br/><br/>5、@Documented&nbsp;&nbsp;表示生产的 javadoc文档中是否也看到注解的说明 <br/><br/>6、@Inherited&nbsp;&nbsp;表示注解是否可以被继承，如果写上了，当前类被注解的时候，子类也拥有了这个注解<br/><br/>7、实现一个简单的注解 <br/>@Target(ElementType.Method) <br/>@Rettention(RetentionPolicy.RUNTIME) <br/>@Documented <br/>@Inherited <br/>public @interface Test&#123; <br/>&nbsp;&nbsp; public void value() default &quot;this is first annation&quot;; <br/>&#125; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>public class TestAnnation&#123; <br/>&nbsp;&nbsp;@Test(value=&quot;this is second annation&quot;) <br/>&nbsp;&nbsp; public void test()&#123; <br/>&nbsp;&nbsp; System.out.println(&quot;asfads&quot;); <br/>&#125; <br/>注解解析原理:主要是通过反射机制，找到当前类，在判断当前类是否有注解！ <br/>&nbsp;&nbsp;public static void main(Stringp[] args)&#123; <br/>&nbsp;&nbsp; Method[] method = Test.class.getDeclaredMethods();&nbsp;&nbsp; <br/>&nbsp;&nbsp; for(Method m:method)&#123; <br/>&nbsp;&nbsp;&nbsp;&nbsp;boolean&nbsp;&nbsp;flag = method.isAnnationPresent(Test); <br/>&nbsp;&nbsp; if(flag)&#123; <br/>&nbsp;&nbsp;&nbsp;&nbsp; Test t = method.getAnnation(Test.class); <br/>&nbsp;&nbsp; System.out.println(&quot;annnation name&quot;+t.getName+&quot;value:&quot;+t.Value()); <br/>&#125; <br/>&nbsp;&nbsp; <br/>&#125; <br/>&nbsp;&nbsp; <br/>&#125; <br/>&#125;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>Tags - <a href="https://www.heckjj.com/tags/java/" rel="tag">java</a> , <a href="https://www.heckjj.com/tags/%25E6%25B3%25A8%25E8%25A7%25A3/" rel="tag">注解</a> , <a href="https://www.heckjj.com/tags/%25E7%25BC%2596%25E7%25A8%258B/" rel="tag">编程</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/java-annotation-summary-html/#blogcomment</link>
<title><![CDATA[[评论] java注解Annation的小结]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/java-annotation-summary-html/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>