草庐IT

javax.annotation : @Nullable vs @CheckForNull

coder 2023-05-14 原文

两者有什么区别?两者似乎都意味着该值可能为空,应进行相应处理,即检查是否为空。

更新: 上面的两个注释是 JSR-305/FindBugs 的一部分: http://findbugs.sourceforge.net/manual/annotations.html

最佳答案

我认为您添加的链接很清楚:如果您使用 @CheckForNull 并且使用该值的代码不检查 null,FindBugs 将显示这是一个错误。

FindBugs 将忽略 @Nullable

In practice this annotation is useful only for overriding an overarching NonNull annotation.

在必须始终检查值的情况下使用 @CheckForNull。使用 @Nullable 其中 null 可能没问题。

编辑:目前看来 @CheckForNull 没有得到很好的支持,所以我建议避免使用它并使用 @NonNull (另见 Which @NotNull Java annotation should I use? )。 另一个想法是直接与 FindBugs 开发人员联系,并询问他们对文档中的不一致之处的意见。

关于javax.annotation : @Nullable vs @CheckForNull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12301570/

有关javax.annotation : @Nullable vs @CheckForNull的更多相关文章

  1. javax 脚本如何从 Java 调用 JavaScript 中的函数 - 2

    我正在尝试通过Java调用JavaScript中的函数。这在直接将脚本作为字符串读取时效果很好,但我使用的是CompiledScripts。当我使用编译脚本执行此操作时,如果我还添加绑定(bind),它会提示找不到方法。没有绑定(bind)它可以工作,但当然函数失败,因为它需要绑定(bind)。有什么想法吗?CompiledScriptscript=...getscript....Bindingsbindings=script.getEngine().createBindings();LoggerscriptLogger=LogManager.getLogger("TEST_SCRIP

  2. javascript - Google Closure Annotating 不会告诉我我错了 - 2

    我正在试用GoogleClosure,特别是用于强制类型安全的注释内容。为了测试我做错了什么,尽管编译器不会告诉我这是...代码如下://==ClosureCompiler==//@output_file_namedefault.js//@compilation_levelSIMPLE_OPTIMIZATIONS//==/ClosureCompiler==/***Acard.*@constructor*@param{String}cardNameTheexactnameofthecard*@param{Kinetic.Layer}layerThelayerforthecard*/fun

  3. javascript - Rhino load() 函数在 javax.script 提供的 JavaScript 中可用吗? - 2

    一些为Rhino的shell开发的JavaScript文件使用load()来加载额外的JavaScript文件。我正在尝试使用javax.script从这些RhinoJavaScript文件之一中嵌入功能。不幸的是,javax.script的JavaScript没有实现load()函数。尝试对包含load()的脚本执行eval()时,会发生以下错误:com.sun.script.javascript.RhinoScriptEngine:-1:in`eval':javax.script.ScriptException:sun.org.mozilla.javascript.internal

  4. javascript - map : Adding html annotation to it or other any other alternative charts - 2

    我正在尝试在地理图表上添加文本叠加层。我只能在工具提示中添加文本,但只有在鼠标悬停/选择时才可见。但我希望它始终可见。下面是fiddle链接。当我尝试添加注释时,geochart出现错误。http://jsfiddle.net/aSrVH/汽车数据=新谷歌。可视化。数据表();Data.addColumn('string','Country');data.addColumn('number','Value');data.addColumn({type:'string',role:'tooltip'});我无法将上面的内容更改为:data.addColumn({type:'string'

  5. xml - 使用 JAXB 时出现 java.net.MalformedURLException : no protocol with javax. xml.stream.XMLStreamException - 2

    我正在使用JAXB解码XML文档。在解析XML时,它会抛出一个用XMLStreamException包装的MalformedURLException。我的理解是在创建XMLStreamReader对象本身时它抛出了异常。有什么建议吗?我使用的代码片段:XMLInputFactoryxif=XMLInputFactory.newFactory();XMLResolverresolver=newXMLResolver();//tocapturesystemID,baseURIetc.xif.setXMLResolver(resolver);//ThrowsMalformedURLExcep

  6. 此上下文已知 javax.xml.bind.MarshalException 及其任何父类(super class) - 2

    我遇到了异常,正在寻找解决方案,我们将不胜感激。在其他一些消息中发现了同样的问题,但它们对我不起作用。请看下面的代码。javax.xml.bind.MarshalException-withlinkedexception:[com.sun.istack.SAXException2:classcom.mycompany.soma.ws.rest.v1.model.test.EmployeeConstructionnoranyofitssuperclassisknowntothiscontext.javax.xml.bind.JAXBException:classcom.mycompany

  7. java - @XmlSchema : "annotation type not applicable to this kind of declaration" - 2

    2.11和java7。我正在尝试使用@XmlSchema注释我的包,如下所示。importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlNsForm;importjavax.xml.bind.annotation.XmlRootElement;importjavax.xml.bind.annotation.XmlSchema;@XmlSchema(namespace="http://www.sitemaps.org/schemas/sitemap/0.9",elementFormDefau

  8. java - axis2 导致 javax.xml.stream.XMLStreamException : element text content may not contain START_ELEMENT - 2

    我通过eclipse生成了一个axis2web服务客户端。我总是在执行时遇到这个错误。org.apache.axis2.AxisFault:javax.xml.stream.XMLStreamException:elementtextcontentmaynotcontainSTART_ELEMENT在我的wsdl中在调试调用时我可以看到响应是Rxxxxxx2016-02-0612:02:53-12xxxxxxxxxxxxxxxx关于java.lang.Stringcontent=reader.getElementText();抛出异常javax.xml.stream.XMLStream

  9. xml - 将相邻的注释转换为 xs :annotations in XSDs - 2

    我有一个XSD,其中包含许多注释,应该将其移至前面的xs:simpleTypes或xs:complexTypes的xs:annotation/xs:documentation部分。如何使用XSLTV1.0或XSLTV2.0移动这些注释?示例输入XSD:输出的XSD应该是:Loremipsumdolorsitamet,consectetueradipiscingelit.Aeneancommodoligulaegetdolor.Aeneanmassa.Cumligula,porttitoreu,consequatvitae,eleifendac,enimEtiamsitametorcie

  10. java - SAXNotRecognizedException : Feature 'http://javax.xml.XMLConstants/feature/secure-processing' not recognized - 2

    我在解码类时收到此错误。我正在使用Amazon的mTurks以及Spring、Maven和(惊喜,惊喜)一个xerces问题已经引起了它的注意。我以多种不同的方式使用POM来尝试解决问题,但我似乎无法找出解决方案。我正在使用在这里找到的mturks的mavenized版本:https://github.com/tc/java-aws-mturk我已经明确地从mturks中排除了xerces的东西:com.amazonjava-aws-mturk1.2.2commons-langcommons-langapache-xercesxercesImplapache-xercesresolve

随机推荐