Viagra For Sale

Tiger中的Annotation又被称作Metadata(关于数据的数据),就是关于源代码的数据,具体来说就是关于Java的类、方法、字段等关联的附加数据。这些数据可以被Java的编译器或者其它工具(比如Java IDE)来发现和使用。


BTW:其实从数据的数据的角度来说,JavaDoc算是最早的Metadata了。 :-)


JUnit4.0中,就改用Annotation来创建单元测试,而不再用"test"开头的函数了。这样更自然,而且更符合标准。


看看J2SE 5.0 in a Nutshell中给出的例子:

Viagra For Sale, [code lang="java"]
import java.lang.annotation.*;
import java.lang.reflect.*;

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface debug {
boolean devbuild() default false;
int counter();
}

public class MetaTest {
final boolean production=true;

@debug(devbuild=production,counter=1) public void testMethod() {
}

public static void main(String[] args) {

MetaTest mt = new MetaTest();
try {
Annotation[] a = mt.getClass().getMethod("testMethod").getAnnotations();
for (int i=0; i System.out.println("a["+i+"]="+a[i]+" ");
}
} catch(NoSuchMethodException e) {
System.out.println(e);
}
}
}
[/code]

这个例子很简单,就是在运行时打印出某个函数的所有的Annotation。


@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)表明这个Annotation作用于RUNTIME级别,相应的还有:



  1. SOURCE:源代码级别,编译后将消失;

  2. CLASS:类文件级别,运行时无法访问;

  3. RUNTIME:运行时级别,运行时依然存在,通过Reflection进行访问。


因此,JavaDoc应该算是Source级别的Annotation,而JUnit 4.0中应该是RUNTIME级别的Annotation。


J2SE5.0中系统定义了三个Annotation:


@Override


顾名思义,用来标识本函数应该是Override父类的。用来在编译时找到一些由于疏忽而造成的在运行期非常难以排查的Bug。比如:


[code lang="java"]
@Override
public int hasCode() {
return toString().hashCode();
}
[/code]

这段代码的本意应该是"hashCode",由于疏忽而写成了"hasCode",这个Bug在运行时非常难找到,而加了Annotation,可以在编译的时候,就能把这个臭虫揪出来,当然,还需要标识所有Override这个良好习惯的养成。


@Deprecated


标识Deprecated函数,编译时给出警告。具体见


@SuppressWarnings


这是用于抑制在J2SE 5.0中的,如果Collection等不使用泛型语法而给出的编译警告信息。具体见


可见,给源代码打上Tag不但能够进行编译期检查,还能进行代码分析以及其它一些应用(单元测试)。


除去这些系统定义的Annotation,我们还可以定义自己的Annotation来帮助自己的工作。


Tiger刚出来的时候,我曾经想自己定义一个Annotation - "DesignPattern",用来标识我的代码中用到的各种Design Pattern,然后再编写一个工具来制作Tag Cosmos。看看我到底用了多少DP,哪些用的最多,呵呵(显然,这是个SOURCE级别的Annotation)。


[code lang="java"]
/**
* Annotation type to indicate a design pattern used
*/
@Retention(RetentionPolicy.SOURCE)
public @interface DesignPattern {
String value();
}
[/code]

与社会性软件(SocailSoftware)中的Tag一样,Java中的Annotation也是将人们对数据的认识以“数据的数据”的方式存储到数据中,用于帮助我们更好的认识事物。不同的是,社会性软件中的Tag更加偏重于让人们根据Tag来进行知识共享,而代码中的Tag更加偏重于利用这些Tag来帮助程序员进行开发或者方便第三方程序进行扩展。


Reference:


JSR 175: A Metadata Facility for the JavaTM Programming Language


J2SE 5.0 in a Nutshell - Calvin Austin


Annotations in Tiger, Part 1: Add metadata to Java code - Brett McLaughlin


Annotations in Tiger, Part 2: Custom annotations - Brett McLaughlin


注释(Annotation)与 ASM - Dennis Sosnoski


xDoclet

. Cheap Viagra no rx. Buy Viagra no prescription. Viagra trusted pharmacy reviews. Viagra canada, mexico, india. Viagra dangers. Online Viagra without a prescription. Buy Viagra without a prescription. Buy Viagra online no prescription. Where can i buy Viagra online. Viagra from canadian pharmacy. Taking Viagra. Is Viagra safe. Viagra price. Order Viagra from United States pharmacy. Buy Viagra without prescription. Purchase Viagra for sale. Viagra online cod. Where can i cheapest Viagra online. Viagra use. After Viagra. Viagra wiki. Viagra forum. Rx free Viagra. Where to buy Viagra. Herbal Viagra. What is Viagra. Viagra blogs. Viagra over the counter. Viagra photos. Online buying Viagra. Viagra price, coupon. Canada, mexico, india. Viagra reviews. Viagra pharmacy. Viagra brand name.

Similar posts: Diclofenac For Sale. Modalert For Sale. Accutane For Sale. Buy Wellbutrin SR Without Prescription. Inderal For Sale. Spiriva dangers. Order Glucophage online c.o.d. Toprol XL no prescription. Clomid images. Kjøpe Allopurinol på nett, köpa Allopurinol online.
Trackbacks from: Viagra For Sale. Viagra For Sale. Viagra For Sale. Viagra For Sale. Viagra For Sale. Online Viagra without a prescription. Japan, craiglist, ebay, overseas, paypal. Retin-A gel, ointment, cream, pill, spray, continuous-release, extended-release. Doses Prednisolone work. Lexapro maximum dosage.

Related entries:

One Response to “Viagra For Sale”

  1. Meng Yan ( 孟岩 ) @ Weblog » Blog Archive » “JUnit4.0 in 10 minutes” learning minutes Says:

    [...] 测试函数名称不用再以"test"开头,而用Annotation"@Test"来修饰; [...]

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI