我看过这个关于如何在 Android 中创建 fragment 的视频,但我无法理解这里 @Nullable 的含义。 同样在视频 (thenewboston) 中,@Nullable 用于参数:
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState)
{
return super.onCreateView(inflater, container, savedInstanceState);
}
但后来当我尝试创建相同的覆盖方法时,Android Studio 生成了这个:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
}
有人可以在这里向我解释一下@Nullable 的用法吗?
最佳答案
表示onCreateView
方法的返回值可以为null
。
Denotes that a parameter, field or method return value can be null.
When decorating a method call parameter, this denotes that the parameter can legitimately be null and the method will gracefully deal with it. Typically used on optional parameters.
When decorating a method, this denotes the method might legitimately return null.
This is a marker annotation and it has no specific attributes.
您可以在此 Android Support Annotation 中找到更多详细信息和示例页
关于java - @Nullable java (android) 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32783752/