搜索

47.4. nullable 选项

download PDF

概述

在某些情况下,让方法参数默认为 null。但默认情况下不允许这样做。如果要允许 Java API 中的一些方法参数使用 null 值,则必须使用 nullableOptions 元素明确声明它。

语法

nullableOptions 元素可使用一个或多个 nullableOption 子元素定义,如下所示:

<nullableOptions>
  <nullableOption>ArgumentName</nullableOption>
  ...
</nullableOptions>

其中 ArgumentName 是 Java API 中的 method 参数的名称。

影响范围

如以下摘录所示,nullableOptions 元素可以选择性地显示为 apis 元素的子项,/或作为 api 元素的子项:

<configuration>
  <apis>
    <api>
      <apiName>...</apiName>
      ...
      <nullableOptions>...</nullableOptions>
    </api>
    ...
    <nullableOptions>...</nullableOptions>
  </apis>
</configuration>

您可以在以下范围中定义 nullableOptions 元素:

  • 作为 api 元素的子项 the nullableOptions 映射只适用于 api 元素指定的 API 类。
  • 作为 apis 元素的子项 the nullableOptions 映射默认应用到所有 API 类,但可以在 api 级别上覆盖。
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.