技术开发 频道

Sun提交JSR-308给JCP


IT168技术新闻】 
    Sun已经将JSR-308提交给了JCP,新提交的JSR-308扩展了Java注释系统,允许注释出现在任何可用的类型上,不仅仅是类/方法/域/变量声明,就像在Java SE 6一样. 

    JSR详细说明了Java 注释的语法,与现存的注释一样,新的JSP语法依靠注释处理器(compiler plug-ins).同时并没有改变Java的编译,加载或者运行时语法.使注释变的更加通用和实用. 

    新的Java语法允许注释加在下列位置: 
    方法接受者: 
    public int size() @Readonly { ... } 
    一般类型变量: 
     Map<@NonNull String, @NonEmpty List<@Readonly Document>> files; 
    数组:
     Document[@Readonly] docs1; 
     Document[][@Readonly] docs2 = new Document[2][@Readonly 12]; 
     (docs1 is an unmodifiable one-dimensional array of mutable Documents. docs2 is a mutable array whose elements are unmodifiable one-dimensional arrays of mutable Documents.) 
    typecasts: 
     myString = (@NonNull String)myObject; 
    类型测试: 
     boolean isNonNull = myString instanceof @NonNull String; 
    对象创建: 
     new @NonEmpty @Readonly List(myNonEmptyStringSet) 
    类型参数绑定: 
     class Folder { ... } 
    类继承: 
     class UnmodifiableList implements @Readonly List<@Readonly T> { ... } 
    throws语句: 
     void monitorTemperature() throws @Critical TemperatureException { ... }
0
相关文章