java - @Nullable java (android) 的含义

标签 java android android-fragments

我看过这个关于如何在 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

来自Android documentation :

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/

相关文章:

java - 如何从nutch访问抓取的内容以进行内容分类

java - 匹配两个字符串,一个与 x,另一个与任意字符

android - 如何在 Android 模拟器中安装 APK 文件?

android - DialogFragment 中的 ViewPager - IllegalStateException : Fragment does not have a view

java - 使用 null 或 0 或 ""初始化变量之间的区别

java - 数字日期格式

android - 重新加载 Webview 用户定义的计时器字符串

android - 如何通过示例在 Android 中实现 Facebook App Link

android - ActionbarSherlock 混淆了 Fragment 的 onAttach() 方法?

android - 如果一个 fragment 不再在前景中,调用哪个方法?