Java 当函数返回类型为Void时,Findbugs警告NP\u NONNULL\u RETURN\u冲突
我有一个函数需要作为可调用函数调用。因为作为可调用函数调用的函数需要有一个返回类型。我将函数的返回类型更改为Java 当函数返回类型为Void时,Findbugs警告NP\u NONNULL\u RETURN\u冲突,java,findbugs,callable,code-standards,Java,Findbugs,Callable,Code Standards,我有一个函数需要作为可调用函数调用。因为作为可调用函数调用的函数需要有一个返回类型。我将函数的返回类型更改为Void。大概是这样的:- public Void myFunction() { // Do somthing. return null; } 但是Findbug将此报告为警告:- NP_NONNULL_RETURN_VIOLATION: Method may return null, but is declared @NonNull This method may
Void
。大概是这样的:-
public Void myFunction() {
// Do somthing.
return null;
}
但是Findbug将此报告为警告:-
NP_NONNULL_RETURN_VIOLATION: Method may return null, but is declared @NonNull
This method may return a null value, but the method (or a superclass method which it overrides) is declared to return @NonNull.
绕过此警告的可能修复方法是:-
@Nullable
注释Optional
并返回Optional.empty()
,但是这种方法的缺点是使函数的调用者不清楚函数约定