`

java5的两个新特性--import static , annotation

 
阅读更多
1import static

如果你在程序中有很多类似Math.PI的常量要使用,就可以使用import static,避免每次都要写Math.PI或
java.lang.Math.PI。
注意:这样的用法只有当你将大量使用 java.lang.Math.PI这类常量的时候才推荐使用,不然容易找成程序的混乱。
例子:
import static java.lang.Math.*;
........
double r = cos(PI * theta);


详见:http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html .


2annotation
annotaion的目的是对java开发提供更好的支持。其使用作用:
Simply speaking,
annotation is a mechanism for associating a meta-tag with program
elements and allowing the compiler or the VM to extract program
behaviors from these annotated elements and generate interdependent
codes when necessary.
这个比较复杂,待续。
参见:
http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html
http://java.sun.com/developer/technicalArticles/J2SE/constraints/annotations.html
http://www.developer.com/java/other/article.php/3556176
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics