﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-ricegun</title><link>http://www.blogjava.net/ricegun/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 03 May 2026 06:28:57 GMT</lastBuildDate><pubDate>Sun, 03 May 2026 06:28:57 GMT</pubDate><ttl>60</ttl><item><title>JDK5.0 Annotation 入门介绍</title><link>http://www.blogjava.net/ricegun/archive/2010/08/04/327904.html</link><dc:creator>第七日</dc:creator><author>第七日</author><pubDate>Wed, 04 Aug 2010 02:22:00 GMT</pubDate><guid>http://www.blogjava.net/ricegun/archive/2010/08/04/327904.html</guid><wfw:comment>http://www.blogjava.net/ricegun/comments/327904.html</wfw:comment><comments>http://www.blogjava.net/ricegun/archive/2010/08/04/327904.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ricegun/comments/commentRss/327904.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ricegun/services/trackbacks/327904.html</trackback:ping><description><![CDATA[<div style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><strong style="font-weight: bold; "><font size="4">背景知识：</font></strong></div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">从JDK5开始提供名为Annotation（注释）的功能，它被定义为JSR-175规范。注释是以&#8220;@注释名&#8221;在代码中存在的，还可以添加一些参数值，例如：@SuppressWarnings(value="unchecked")。注释可以附加在package, class, method, field等上面，相当于给它们添加了额外的辅助信息，我们可以通过反射机制编程实现对这些元数据的访问。如果没有外部解析工具等对其加以解析和处理的情况，本身不会对Java的源代码或class文件等产生任何影响，也不会对它们的执行产生任何影响。</div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">元数据的作用，大致可分为三种：编写文档，通过代码里标识的元数据生成文档；代码分析，通过代码里标识的元数据对代码进行分析；编译检查，通过代码里标识的元数据让编译器能实现基本的编译检查。</div>
<div style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><strong style="font-weight: bold; "><font size="4">JDK5内置的基本注释</font></strong></div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">JDK5内置了一些常用的注释，可以在编译时帮我们捕获部分编译错误，及提示信息，下面介绍下这些注释的用法：</div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">1、@Override定义在java.lang.Override中，此注释只适用于修辞方法，表示一个方法声明打算重写超类中的另一个方法声明。如果方法利用此注释类型进行注解但没有重写超类方法，则编译器会生成一条错误消息。例如我们为某类重写toString()方法却写成了tostring()，并且我们为该方法添加了@Override注释；代码如下：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">public class OverrideDemo {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp; &nbsp;@Override</span></div>
            <div style="margin-left: 21pt; text-indent: 21pt; "><span style="color: white; ">public String tostring() {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return super.toString();</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; }</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">}</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">在编译时，会提示以下错误信息：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">OverrideTest.java:4:&nbsp;</span><span style="color: white; ">方法未覆盖其父类的方法</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Override</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^1&nbsp;</span><span style="color: white; ">错误</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">2、@Deprecated定义在java.lang.Deprecated中，此注释可用于修辞方法、属性、类，表示不鼓励程序员使用这样的元素，通常是因为它很危险或存在更好的选择。在使用不被赞成的程序元素或在不被赞成的代码中执行重写时，编译器会发出警告。使用@Deprecated的示例代码如下：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">public class DeprecatedDemo {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DeprecatedClass.DeprecatedMethod();</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; }</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">}</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">class DeprecatedClass {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; @Deprecated</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; public static void DeprecatedMethod() {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; }</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">}</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">在编译时，会得到以下提示信息：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">注意：</span><span style="color: white; ">DeprecatedDemo.java&nbsp;</span><span style="color: white; ">使用或覆盖了已过时的</span><span style="color: white; ">&nbsp;API</span><span style="color: white; ">。</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">注意：要了解详细信息，请使用</span><span style="color: white; ">&nbsp;-Xlint:deprecation&nbsp;</span><span style="color: white; ">重新编译。</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">如果在编译时添加-Xlint:deprecation参数，我们能更清楚的看到该警告的详细信息，如下：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="line-height: 18px; "><strong style="font-weight: bold; "><span style="color: white; ">DeprecatedDemo.java:6:&nbsp;</span></strong><strong style="font-weight: bold; "><span style="color: white; ">警告：</span></strong><strong style="font-weight: bold; "><span style="color: white; ">[deprecation] SomeClass&nbsp;</span></strong><strong style="font-weight: bold; "><span style="color: white; ">中的</span></strong><strong style="font-weight: bold; "><span style="color: white; ">&nbsp;DeprecatedMethod()&nbsp;</span></strong><strong style="font-weight: bold; "><span style="color: white; ">已过时</span></strong></div>
            <div style="line-height: 18px; "><strong style="font-weight: bold; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomeClass.DeprecatedMethod();</span></strong></div>
            <div style="line-height: 18px; "><strong style="font-weight: bold; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^1&nbsp;</span></strong><strong style="font-weight: bold; "><span style="color: white; ">警告</span></strong></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">要注意@Deprecated与@deprecated的区别，@deprecated是为了生成文档的需要，例如：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">class DeprecatedClass {</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;/**</span></div>
            <div style="text-indent: 42pt; "><span style="color: white; ">* @deprecated&nbsp;</span><span style="color: white; ">此方法已过时，不建议使用</span></div>
            <div style="text-indent: 42pt; "><span style="color: white; ">*/</span></div>
            <div style="text-indent: 36.75pt; "><span style="color: white; ">@Deprecated</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; public static void DeprecatedMethod() {</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">&nbsp;&nbsp;&nbsp; }</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">}</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">&nbsp;3、@SuppressWarnings定义在java.lang.SuppressWarnings中，用来抑制编译时的警告信息。与前两个注释有所不同，你需要添加一个参数才能正确使用，这些参数值都是已经定义好了的，我们选择性的使用就好了，参数如下：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div align="center"><strong style="font-weight: bold; "><span style="font-size: 12pt; color: white; ">参数</span></strong></div>
            </td>
            <td valign="top" width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div align="center"><strong style="font-weight: bold; "><span style="font-size: 12pt; color: white; ">说明</span></strong></div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>deprecation</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>使用了过时的类或方法时的警告</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>unchecked</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>执行了未检查的转换时的警告，例如当使用集合时没有用泛型 (Generics) 来指定集合保存的类型</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>fallthrough</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>当 Switch 程序块直接通往下一种情况而没有 Break 时的警告</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>path</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>在类路径、源文件路径等中有不存在的路径时的警告</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>serial</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>当在可序列化的类上缺少 serialVersionUID 定义时的警告</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>finally</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>任何 finally 子句不能正常完成时的警告</div>
            </td>
        </tr>
        <tr>
            <td width="121" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 90.45pt; padding-top: 0cm; ">
            <div>all</div>
            </td>
            <td width="448" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 335.65pt; padding-top: 0cm; ">
            <div>关于以上所有情况的警告</div>
            </td>
        </tr>
    </tbody>
</table>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">通过上面的表格，你应该了解到每个参数的用意了，下面我就以一个常用的参数unchecked为例，为你展示如何使用@SuppressWarnings注释，示例代码如下：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">import java.util.List;</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">import java.util.ArrayList;</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">public class SuppressWarningsDemo {</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static List cache = new ArrayList();</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //@SuppressWarnings(value = "unchecked")</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void add(String data) {</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cache.add(data);</span></div>
            <div><span style="color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">}</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">当我们不使用@SuppressWarnings注释时，编译器就会有如下提示：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div style="text-indent: 21pt; "><span style="color: white; ">注意：</span><span style="color: white; ">SuppressWarningsDemo.java&nbsp;</span><span style="color: white; ">使用了未经检查或不安全的操作。</span></div>
            <div style="text-indent: 21pt; "><span style="color: white; ">注意：要了解详细信息，请使用</span><span style="color: white; ">&nbsp;-Xlint:unchecked&nbsp;</span><span style="color: white; ">重新编译。</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">下面我们去掉@SuppressWarnings(value="unchecked")这一行的注释符&#8220;//&#8221;，它会屏蔽编译时的警告信息，这也就是它所要达到的目的。</div>
<div style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;另外，由于@SuppressWarnings注释只有一个参数，并且参数名为value，所以我们可以将上面一句注释简写为@SuppressWarnings("unchecked")；<br />
同时参数value可以取多个值如：@SuppressWarnings(value={"unchecked", "deprecation"})<br />
或@SuppressWarnings({"unchecked", "deprecation"})。</div>
<div style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><strong style="font-weight: bold; "><font size="4">自定义Annotation注释</font></strong></div>
<div align="left" style="margin-bottom: 12pt; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">1、注释annotation与接口的异同：</div>
<div align="left" style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">因为annotation类型是一个非凡的接口，所以它与接口之间存在着某些差异：</div>
<div align="left" style="margin-left: 42pt; text-indent: -21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">A.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Annotation类型使用关键字@interface而不是interface，这个关键字声明隐含了一个信息，它是继承了java.lang.annotation.Annotation接口，并非声明了一个interface。</div>
<div align="left" style="margin-left: 42pt; text-indent: -21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">B.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Annotation类型的方法定义是独特的、受限制的，方法必须声明为无参数、无异常抛出的。这些方法定义了annotation的成员：方法名成为了成员名，而方法返回值成为了成员的类型。而方法返回值类型必须为primitive类型、Class类型、枚举类型、annotation类型或者由前面类型之一作为元素的一维数组。方法的后面可以使用default和一个默认数值来声明成员的默认值，null不能作为成员默认值，这与我们在非annotation类型中定义方法有很大不同。</div>
<div align="left" style="margin-left: 42pt; text-indent: -21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">C.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Annotation类型又与接口有着近似之处，它们可以定义常量、静态成员类型（比如枚举类型定义）。Annotation类型也可以如接口一般被实现或者继承。</div>
<div align="left" style="margin-bottom: 12pt; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">2、自定义注释的实例：</div>
<div align="left" style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">下面，我们将看到如何定义annotation类型的例子。它展示了annotation类型声明以及@interface与interface之间的不同：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">import java.lang.annotation.*;</span></div>
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">/**<br />
            *&nbsp;</span><span style="color: white; ">使用</span><span style="color: white; ">annotation</span><span style="color: white; ">来描述那些被标注的成员是不稳定的，需要更改</span><span style="color: white; "><br />
            */<br />
            public @interface Unstable {</span></div>
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">}</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">下面的另一个例子只定义了一个成员。并通过将这个成员命名为value，使我们可以方便的使用这种annotation的快捷声明方式：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">/**<br />
            *&nbsp;</span><span style="color: white; ">使用</span><span style="color: white; ">Author</span><span style="color: white; ">这个</span><span style="color: white; ">annotation</span><span style="color: white; ">定义在程序中指出代码的作者</span><span style="color: white; "><br />
            */<br />
            public @interface Author {<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</span><span style="color: white; ">返回作者名</span><span style="color: white; ">&nbsp;*/<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String value();<br />
            }</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">以下的例子更加复杂。Reviews annotation类型只有一个成员，但是这个成员的类型是复杂的：由Review annotation组成的数组。Review annotation类型有3个成员：枚举类型成员grade、表示Review名称的字符串类型成员Reviewer、具有默认值的字符串类型成员 Comment。</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">/**<br />
            * Reviews annotation</span><span style="color: white; ">类型只有一个成员，</span><span style="color: white; "><br />
            *&nbsp;</span><span style="color: white; ">但是这个成员的类型是复杂的：由</span><span style="color: white; ">Review annotation</span><span style="color: white; ">组成的数组</span><span style="color: white; "><br />
            */<br />
            @Retention(RetentionPolicy.RUNTIME)<br />
            public @interface Reviews {<br />
            &nbsp;&nbsp;&nbsp; Review[] value();<br />
            }</span></div>
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">/**<br />
            * Review annotation</span><span style="color: white; ">类型有</span><span style="color: white; ">3</span><span style="color: white; ">个成员：</span><span style="color: white; ">&nbsp;<br />
            *&nbsp;</span><span style="color: white; ">枚举类型成员</span><span style="color: white; ">grade</span><span style="color: white; ">、</span><span style="color: white; "><br />
            *&nbsp;</span><span style="color: white; ">表示</span><span style="color: white; ">Review</span><span style="color: white; ">名称的字符串类型成员</span><span style="color: white; ">Reviewer</span><span style="color: white; ">、</span><span style="color: white; "><br />
            *&nbsp;</span><span style="color: white; ">具有默认值的字符串类型成员</span><span style="color: white; ">Comment</span><span style="color: white; ">。</span><span style="color: white; "><br />
            */<br />
            public @interface Review {<br />
            &nbsp;&nbsp;&nbsp; //&nbsp;</span><span style="color: white; ">内嵌的枚举类型</span><span style="color: white; "><br />
            &nbsp;&nbsp;&nbsp;&nbsp; public static enum Grade { EXCELLENT, SATISFACTORY, UNSATISFACTORY };<br />
            &nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;</span><span style="color: white; ">下面的方法定义了</span><span style="color: white; ">annotation</span><span style="color: white; ">的成员</span><span style="color: white; "><br />
            &nbsp;&nbsp;&nbsp; &nbsp;Grade grade();<br />
            &nbsp;&nbsp;&nbsp;&nbsp; String reviewer();<br />
            &nbsp;&nbsp;&nbsp; &nbsp;String comment() default "";<br />
            }</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">最后，我们来定义一个annotation方法用于罗列出类运行中所有的unchecked异常。这个 annotation类型将一个数组作为了唯一的成员。数组中的每个元素都是异常类。为了加强对未检查的异常（此类异常都是在运行时抛出）进行报告，我们可以在代码中对异常的类型进行限制：</div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <div align="left" style="margin-bottom: 12pt; "><span style="color: white; ">public @interface UncheckedExceptions {&nbsp;<br />
            &nbsp;&nbsp;&nbsp;&nbsp; Class&lt;? extends RuntimeException&gt;[] value();<br />
            }</span></div>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><strong style="font-weight: bold; "><span style="font-size: 16pt; line-height: 31px; ">Meta-Annotation</span></strong><strong style="font-weight: bold; "><span style="font-size: 16pt; line-height: 31px; ">类型</span></strong><span style="font-size: 16pt; line-height: 31px; ">：</span></div>
<div align="left" style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">Annotation 类型可以被它们自己所标注。Java5.0定义了4个标准的meta-annotation类型，分别是：Target、Retention、Documented、Inherited，它们被用来提供对其它annotation类型作说明。 这些类型和它们所支持的类在java.lang.annotation包中可以找到。</div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">@</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">Target</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">的用法：</span></strong><span style="font-size: 10.5pt; line-height: 21px; ">指示注释类型所适用的程序元素的种类。如果注释类型声明中不存在</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;Target&nbsp;</span><span style="font-size: 10.5pt; line-height: 21px; ">元注释，则声明的类型可以用在任一程序元素上。如果存在这样的元注释，则编译器强制实施指定的使用限制。</span><span style="font-size: 10.5pt; line-height: 21px; ">例如，以下这个注释只能用来声明方法</span><span style="font-size: 10.5pt; line-height: 21px; ">：</span></div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <pre style="font-family: monospace; font-size: 1em; text-indent: 15.75pt; "><span style="font-size: 10.5pt; color: white; ">@Target(ElementType.METHOD)</span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp; public @interface MyAnnotation {</span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... </span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;}</span></pre>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">java.lang.annotation.<span style="line-height: 18px; ">ElementType</span><span style="line-height: 18px; ">是一个枚举类型，它具有以下定义：</span></div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div align="center"><strong style="font-weight: bold; "><span style="color: white; ">ElementType</span></strong><strong style="font-weight: bold; "><span style="color: white; ">值</span></strong></div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div align="center"><strong style="font-weight: bold; "><span style="color: white; ">说明</span></strong></div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.ANNOTATION_TYPE</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于注释类型声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.CONSTRUCTOR</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>构造方法声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.FIELD</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于字段声明（包括枚举常量）</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.LOCAL_VARIABLE</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于局部变量声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.METHOD</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于方法声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.PACKAGE</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于包声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.PARAMETER</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于参数声明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="225" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 168.45pt; padding-top: 0cm; ">
            <div>ElementType.TYPE</div>
            </td>
            <td valign="top" width="344" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 257.65pt; padding-top: 0cm; ">
            <div>应用于类、接口（包括注释类型）或枚举声明</div>
            </td>
        </tr>
    </tbody>
</table>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;<strong style="font-weight: bold; ">@</strong></span><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">Retention</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">的用法</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">：</span></strong><span style="font-size: 10.5pt; line-height: 21px; ">指示注释类型的注释要保留多久。如果注释类型声明中不存在</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;Retention&nbsp;</span><span style="font-size: 10.5pt; line-height: 21px; ">注释，则保留策略默认为</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;<tt><span style="line-height: 21px; ">RetentionPolicy.CLASS</span></tt></span><span style="font-size: 10.5pt; line-height: 21px; ">，例如：</span></div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td valign="top" width="568" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; ">
            <pre style="font-family: monospace; font-size: 1em; text-indent: 15.75pt; "><span style="font-size: 10.5pt; color: white; ">@ Retention(</span><span style="font-size: 9pt; color: white; ">RetentionPolicy.CLASS</span><span style="font-size: 10.5pt; color: white; ">)</span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp; public @interface MyAnnotation {</span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... </span></pre>
            <pre style="font-family: monospace; font-size: 1em; "><span style="font-size: 10.5pt; color: white; ">&nbsp;&nbsp;&nbsp;&nbsp;}</span></pre>
            </td>
        </tr>
    </tbody>
</table>
<div align="left" style="line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 18px; ">java.lang.annotation.</span><span style="line-height: 18px; ">RetentionPolicy</span><span style="line-height: 18px; ">是一个枚举类型，它具有以下定义：</span></div>
<table cellspacing="0" border="1" cellpadding="0" style="border-collapse: collapse; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td width="177" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 133pt; padding-top: 0cm; ">
            <div><strong style="font-weight: bold; "><span style="color: white; ">RetentionPolicy</span></strong><strong style="font-weight: bold; "><span style="color: white; ">值</span></strong></div>
            </td>
            <td width="391" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #9bbb59; padding-bottom: 0cm; width: 293.1pt; padding-top: 0cm; ">
            <div><strong style="font-weight: bold; "><span style="color: white; ">说明</span></strong></div>
            </td>
        </tr>
        <tr>
            <td width="177" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 133pt; padding-top: 0cm; ">
            <div><strong style="font-weight: bold; ">RetentionPolicy.CLASS</strong></div>
            </td>
            <td width="391" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 293.1pt; padding-top: 0cm; ">
            <div>编译器将把注释记录在类文件中，但在运行时 VM 不需要保留注释</div>
            </td>
        </tr>
        <tr>
            <td width="177" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 133pt; padding-top: 0cm; ">
            <div><strong style="font-weight: bold; ">RetentionPolicy.RUNTIME</strong></div>
            </td>
            <td width="391" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 293.1pt; padding-top: 0cm; ">
            <div>编译器将把注释记录在类文件中，在运行时 VM 将保留注释，因此可以反射性地读取</div>
            </td>
        </tr>
        <tr>
            <td width="177" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 133pt; padding-top: 0cm; ">
            <div><strong style="font-weight: bold; ">RetentionPolicy.SOURCE</strong></div>
            </td>
            <td width="391" style="font-size: 1em; padding-right: 5.4pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e6eed5; padding-bottom: 0cm; width: 293.1pt; padding-top: 0cm; ">
            <div>编译器要丢弃的注释</div>
            </td>
        </tr>
    </tbody>
</table>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">@</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">Documented</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">的用法：</span></strong><span style="font-size: 10.5pt; line-height: 21px; ">指示某一类型的注释将通过</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;javadoc&nbsp;</span><span style="font-size: 10.5pt; line-height: 21px; ">和类似的默认工具进行文档化。应使用此类型来注释这些类型的声明：其注释会影响由其客户端注释的元素的使用。如果类型声明是用</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;Documented&nbsp;</span><span style="font-size: 10.5pt; line-height: 21px; ">来注释的，则其注释将成为注释元素的公共</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;API&nbsp;</span><span style="font-size: 10.5pt; line-height: 21px; ">的一部分。</span><span style="font-size: 10.5pt; line-height: 21px; ">Documented</span><span style="font-size: 10.5pt; line-height: 21px; ">是一个没有成员的注释。</span></div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">@</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">Inherited</span></strong><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">的用法：</span></strong><span style="font-size: 10.5pt; line-height: 21px; ">指示注释类型自动被子类继承。</span><span style="font-size: 10.5pt; line-height: 21px; ">&nbsp;Inherited</span><span style="font-size: 10.5pt; line-height: 21px; ">也</span><span style="font-size: 10.5pt; line-height: 21px; ">是一个没有成员的注释。</span></div>
<div style="text-indent: 21pt; line-height: 18px; font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; "><span style="font-size: 10.5pt; line-height: 21px; ">注意，如果使用</span><strong style="font-weight: bold; "><span style="font-size: 10.5pt; line-height: 21px; ">@Inherited</span></strong><span style="font-size: 10.5pt; line-height: 21px; ">注释类以外的任何事物都是无效的。还要注意，此元注释仅对从超类继承注释有效；对已实现接口的注释无效。</span></div>
<img src ="http://www.blogjava.net/ricegun/aggbug/327904.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ricegun/" target="_blank">第七日</a> 2010-08-04 10:22 <a href="http://www.blogjava.net/ricegun/archive/2010/08/04/327904.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>怎么用javascript做数据的格式化</title><link>http://www.blogjava.net/ricegun/archive/2007/01/05/91889.html</link><dc:creator>第七日</dc:creator><author>第七日</author><pubDate>Fri, 05 Jan 2007 01:22:00 GMT</pubDate><guid>http://www.blogjava.net/ricegun/archive/2007/01/05/91889.html</guid><wfw:comment>http://www.blogjava.net/ricegun/comments/91889.html</wfw:comment><comments>http://www.blogjava.net/ricegun/archive/2007/01/05/91889.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/ricegun/comments/commentRss/91889.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ricegun/services/trackbacks/91889.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center">
				<font size="3">
						<strong>
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" mso-bidi-font-size:="" 10.5pt?="">怎么用</span>
						</strong>
						<strong>
								<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
										<font face="Times New Roman">javascript</font>
								</span>
						</strong>
						<strong>
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" mso-bidi-font-size:="" 10.5pt?="">做数据的格式化</span>
						</strong>
						<strong>
								<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
										<?XML:NAMESPACE PREFIX = O /?>
										<o:p>
										</o:p>
								</span>
						</strong>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center">
				<span lang="EN-US" style="FONT-SIZE: 9pt; mso-bidi-font-weight: bold">
						<o:p>
								<font face="Times New Roman"> </font>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center">
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" mso-bidi-font-weight:="" bold;="" roman\??="">作者：老</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; mso-bidi-font-weight: bold">
						<font face="Times New Roman">K<o:p></o:p></font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<strong>
						<span lang="EN-US" style="FONT-SIZE: 9pt">
								<span style="mso-tab-count: 1">
										<font face="Times New Roman">         </font>
								</span>
						</span>
				</strong>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">我们在项目中都有用过金额数字及日期等数据格式化输出显示，比如前面加上“￥”，数值取小数点后两位，短日期时间等。一般的高级语言及开发工具都有提供相应的转换函数如</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">format</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">之类，可是我在最近做</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">web</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">网上银行相关的系统时，却遇到这个很麻烦的问题，就是</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">javascript</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">不提供这种</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">format</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">函数，查了些资料，知道</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">vbscript</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">是有格式化函数的，可是</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">vbscript</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">是微软专用的，无奈只好用正则表达式，可正则表达式也不能够很通用地解决各种类型转换问题，真的是很郁闷，无意中找到看到一个</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">AJAX</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">开发工具的演示（工具下载地址是<a href="http://cn.joyistar.com/"><strong>点击链接</strong></a>），看到它的数据有显示“￥”和数值小数点后两位格式化，马上下载了看了下，发现它居然是用</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">javascript+XSL</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">实现了通用的格式化函数，下载</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">AJAX WebShop</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">后，我找到它的</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">system.js</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">这个文件，打开找到以下函数：</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<table class="MsoNormalTable" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellspacing="0" cellpadding="0" border="1">
				<tbody>
						<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
								<td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #d9d9d9; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; mso-border-alt: solid windowtext .5pt" valign="top" width="568">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">function FormatFloat(value,mask)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">{<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>return BasicFormat(value,mask,'FormatNumber')<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">}<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">function FormatDate(varDate, bstrFormat, varDestLocale)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">{<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>return BasicFormat(varDate,bstrFormat,'FormatDate',varDestLocale);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">}<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">function FormatTime(varTime, bstrFormat, varDestLocale)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">{<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>return BasicFormat(varTime,bstrFormat,'FormatTime',varDestLocale);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">}<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">function BasicFormat(value,mask,action,param)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">{<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>var xmlDoc;<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>var xslDoc;<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>var v='<formats><format><value>'+value+'</value><mask>'+mask+'</mask></format></formats>';<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>xmlDoc=parseXML(v);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<o:p>
																<font face="Times New Roman"> </font>
														</o:p>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>var x; <o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>if(isIE)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>x='<xsl:stylesheet xmlns:xsl="uri:xsl">'<o:p></o:p></xsl:stylesheet></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>else<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>x='<?XML:NAMESPACE PREFIX = XSL /?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">';<o:p></o:p></xsl:stylesheet></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>x+='<xsl:template match="/">';<o:p></o:p></xsl:template></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>if(isIE) {<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>x+='<xsl:eval>'+action+'('+value+',"'+mask+'"';<o:p></o:p></xsl:eval></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>if(param)x+=','+param;<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>x+=')';<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>}<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>else<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>x+='<xsl:value -of="" select="format-number(\" +value+\?,\\?\?+mask+\?\\?)?=""></xsl:value>';<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<o:p>
																<font face="Times New Roman"> </font>
														</o:p>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>x+='';<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>xslDoc=parseXML(x);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>var s;<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>if(isIE)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>
																<span style="mso-spacerun: yes"> </span>s= xmlDoc.transformNode(xslDoc)<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>else{<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>//for mozilla/netscape <o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-spacerun: yes">        </span>var processor = new XSLTProcessor(); <o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>processor.importStylesheet(xslDoc);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 2">                   </span>var result = processor.transformToFragment(xmlDoc, xmlDoc);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-spacerun: yes">        </span>var xmls = new XMLSerializer(); <o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-spacerun: yes">        </span>s = xmls.serializeToString(result);<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>}<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">
																<span style="mso-tab-count: 1">         </span>return s;<o:p></o:p></font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
												<span lang="EN-US" style="FONT-SIZE: 9pt">
														<font face="Times New Roman">}<o:p></o:p></font>
												</span>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">看来他们对</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">xsl</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">用得可真是出神入化了，居然这样就可以实现很通用的格式化转换了，当然不客气了，直接加到我的函数库中哈。</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<span style="mso-tab-count: 1">
								<font face="Times New Roman">         </font>
						</span>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">这个代码偶没有看得很懂，不过确实很管用，请对</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt">
						<font face="Times New Roman">XSL</font>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: \" times="" mso-hansi-font-family:="" \?times="" new="" roman\?;="" roman\??="">精通的朋友分析下也好让我们学习下。</span>
		</p>
<img src ="http://www.blogjava.net/ricegun/aggbug/91889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ricegun/" target="_blank">第七日</a> 2007-01-05 09:22 <a href="http://www.blogjava.net/ricegun/archive/2007/01/05/91889.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>