는 그 단순화는 같이 보입니다, 복잡한 검증 시스템의 비트가 다음@NotNull을 사용하고 메서드 호출 전에 다른 메서드에서 null을 검사 할 때 null 경고를 피하는 방법은 무엇입니까?
private static void mainMethod(@Nullable String startParam, @Nullable String nextParam) {
String nextStep = methodSelect(startParam, nextParam);
switch (nextStep) {
case "none":
break;
case "goFinal":
finalMethod(startParam);
break;
case "goNext":
nextMethod(nextParam);
break;
}
}
private static void nextMethod(@NotNull String nextParam) {
System.out.println(nextParam);
}
private static void finalMethod(@NotNull String startParam) {
System.out.println(startParam);
}
@NotNull
private static String methodSelect(@Nullable String startParam,@Nullable String nextParam) {
if (startParam == null && nextParam == null) {
return "none";
} if (startParam == null) {
return "goNext";
} else {
return "goFinal";
}
}
하지만 경고를 얻을 때 finalMethod()와 nextMethod() 인수 X의 힘 "에 대해 모두를 호출 스위치 문에서 methodSelect() 및 이후의 switch 문이 이러한 인수가 null이 아니더라도 "null"이 될 수 있습니다. 어떻게 이러한 경고를 제거 할 수 있습니까?이 방법으로 또는 이전에 null을 확인하지 않고도 가능합니까? 감사!
나는하게 IntelliJ IDEA 2016년 3월 4일, 자바 (8) 및 주석을 사용하고 있습니다 :
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
대단히 감사합니다! –