日期:2014-05-16  浏览次数:20407 次

JSR305 有助于提高代码健壮性
JSR305 有助于提高代码健壮性

下载(java5+ ,据说java7 内置了)
<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
    <version>1.3.9</version>
    <scope>compile</scope>
</dependency>


使用(eclipse)
/**
 * null to empty
 * 
 * @param s @Nullable the string
 * @return @Nullable the string
 */
@Nonnull
public static String nullToEmpty(@Nullable String s) {
    return s == null ? EMPTY : s;
}


效果(Javadoc和Eclipse提示)

@Nonnull
public static String nullToEmpty(@Nullable String s)

null to empty

Parameters:
    s - @Nullable the string
Returns:
    @Nullable the string

【注】
eclipse提示中,方法签名中不显示@Nullable注解,也许以后会支持吧
public static String nullToEmpty( String s)