首页 \ 问答 \ 我们应该总是使用@NotNull还是@Nullable?(Should we always use @NotNull or @Nullable?)

我们应该总是使用@NotNull还是@Nullable?(Should we always use @NotNull or @Nullable?)

我们是否应该始终在方法参数中使用@NotNull@Nullable ,即使它看起来很明显?

@NotNull
public static int add(@NotNull int a, @NotNull int b) {
    return a + b;
}

澄清:

现在我知道一个不能将null传递给原始变量,但我想问一下,如果我有一个可以传递null的方法(使用非原始参数),但是从方法的名称可以看出,你不能传递null,例如,你不能添加一些东西为null

@NotNull
public static Integer add(@NotNull Integer a, @NotNull Integer b) {
    return a + b;
}

Should we always use @NotNull or @Nullable in method parameters even if it appears to be obvious?

@NotNull
public static int add(@NotNull int a, @NotNull int b) {
    return a + b;
}

To clarify:

Now I know that one can't pass null to primitive variable but I wanted to ask what if I would have a method (with non-primitive parameters) to which null can be passed but from the name of the method it would be obvious that you can't pass null because for example, you can't add something to null?

@NotNull
public static Integer add(@NotNull Integer a, @NotNull Integer b) {
    return a + b;
}

原文:https://stackoverflow.com/questions/38675938
更新时间:2023-05-11 21:05

相关问答

更多
  • 拳头你必须添加iTextSharp dll然后你必须添加一些包: using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html; using iTextSharp.text.xml; using iTextSharp.text.html.simpleparser; 然后根据你的问题。 你想动态传递值,所以我发布一些语法为例: // Create a Document object va ...
  • 你真的不需要控制器动作来做到这一点。 你可以简单地说: Open mypdffile.pdf 当然,如果您想要隐藏用户的这个地址,您可以使用WebClient在服务器上获取它: public ActionResult GetPDF() { using (var client = new WebClient()) { var buffer = client.Download ...
  • 如果您发送的数据位于Telerik网格中,则可以简单地尝试执行此操作: http : //demos.telerik.com/kendo-ui/grid/pdf-export 另一方面,您也可以尝试使用aspose: https ://www.aspose.com/products/pdf/net I fixed it by generating a PDF from scratch using telerik controls.
  • 您可以在新窗口中打开PDF: 这不会托管 PDF,而是提供文件以供本地计算机的查看器执行。 这可能是一个浏览器插件,或者它可能在浏览器之外。 You could open the PDF in a new window:
  • 在iframe中显示PDF 使用上面的链接,我能够在iframe中显示PDF,然后我添加了一个关闭页面的关闭按钮。 Display PDF in iframe Using the link above I was able to get the PDF displayed in an iframe and then I added a Close button that closes the page.
  • 您可以使用iText#,它基于类似的Java项目。 http://itextsharp.sourceforge.net/ 您不需要结合使用Crystal Reports。 如果你需要更强大(但价格昂贵)的东西,我已经用它来复杂的PDF取得了巨大的成功: http://www.pdflib.com/ You can use iText#, it's based on a similar Java project. http://itextsharp.sourceforge.net/ You don't nee ...
  • 我之前使用iTextSharp来做这个,基本上创建一个新的输出pdf然后读入新文档并循环页面将页面添加到新的输出文档。 这甚至可以维护每个页面的页面大小和方向信息。 以下是将pdf添加到输出的代码: int pc = pdfReader.NumberOfPages; int p, rotation; Rectangle box; PdfImportedPage page; for (p = 0; p < pc; p++) { pageNo++; ...
  • 如果e.CommandArgument没有有效的文件名,那么代码失败的唯一原因就是。 我认为Command Argument由于某种原因没有通过 ,请查看你的标记。 您必须为LinkButton显式指定CommandArgument ,如下所示: CommandArgument='<%# Eval("File") %>' The only reason your code could fail would be if e.CommandArgument doesn't have a valid file ...
  • 据我所知,直接通过ajax打开文件并不容易。 所以我建议另一条路线。 当jquery发送ajax来生成pdf而不是返回File时,返回一个指向该文件的链接 ,在该链接中可以在新选项卡中打开该链接,如url。 因此,首先更改您的操作以返回链接: public ActionResult GenerateReport(string Param) { // same as before .... // save your pdf to a file File.WriteAllBytes("resu ...
  • 这最终证明与我正在为我的内容提供的默认压缩有关。 一旦我将“.pdf”添加到不压缩的文件列表中,我的错误就消失了,我可以按照预期愉快地提供PDF内容。 如果有人通过谷歌搜索结果找到了解决上述错误的问题,我会先看看你的内容是如何加密的,以及是否会导致在类似我的情况下提供PDF文件的问题。 This ultimately turned out to be related to the default compression that I was serving my content with. As soon ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)