JSR305 有助于提高代码健壮性
[b]下载(java5+ ,据说java7 内置了)[/b]
[b]使用(eclipse)[/b]
[b]效果(Javadoc和Eclipse提示)[/b]
[color=blue]@Nonnull[/color]
public static String [b]nullToEmpty[/b]([color=blue]@Nullable[/color] String s)
null to empty
[b]Parameters:[/b]
s - @Nullable the string
[b]Returns:[/b]
@Nullable the string
[b]【注】[/b]
eclipse提示中,方法签名中不显示[color=blue]@Nullable[/color]注解,也许以后会支持吧
public static String [b]nullToEmpty[/b]( String s)
[b]下载(java5+ ,据说java7 内置了)[/b]
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
<scope>compile</scope>
</dependency>
[b]使用(eclipse)[/b]
/**
* 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;
}
[b]效果(Javadoc和Eclipse提示)[/b]
[color=blue]@Nonnull[/color]
public static String [b]nullToEmpty[/b]([color=blue]@Nullable[/color] String s)
null to empty
[b]Parameters:[/b]
s - @Nullable the string
[b]Returns:[/b]
@Nullable the string
[b]【注】[/b]
eclipse提示中,方法签名中不显示[color=blue]@Nullable[/color]注解,也许以后会支持吧
public static String [b]nullToEmpty[/b]( String s)
本文介绍JSR305(适用于Java 5及以上版本,Java 7已内置)如何通过@Nullable和@Nonnull等注解增强代码的健壮性。在Eclipse环境中,这些注解可以提供更好的代码提示和文档支持。
668

被折叠的 条评论
为什么被折叠?



