当前位置: 首页 > news >正文

办公室平面设计图seo服务方案

办公室平面设计图,seo服务方案,大连建设网官网首页,网站有什么模块java中集合判空我以前曾在Java Collections类的实用程序上进行过博客撰写#xff0c;并且特别地在使用Usings Collections Methods上的博客emptyList#xff08;#xff09;#xff0c;emptyMap#xff08;#xff09;和emptySet#xff08;#xff09;上进行了博客撰写… java中集合判空 我以前曾在Java Collections类的实用程序上进行过博客撰写并且特别地在使用Usings Collections Methods上的博客emptyListemptyMap和emptySet上进行了博客撰写。 在本文中我将探讨使用Collections类的相关字段访问空集合与使用Collections类的相关方法访问空集合之间有时细微但重要的区别。 以下代码演示了直接访问Collections的字段以指定空集合。 将集合的字段用于空集合 /*** Instantiate my collections with empty versions using Collections fields.* This will result in javac compiler warnings stating warning: [unchecked]* unchecked conversion.*/public void instantiateWithEmptyCollectionsFieldsAssigment(){this.stringsList Collections.EMPTY_LIST;this.stringsSet Collections.EMPTY_SET;this.stringsMap Collections.EMPTY_MAP; } 上面的代码使用javac进行编译 但是导致出现警告消息在这种情况下该消息由NetBeans和Ant生成 -do-compile:[javac] Compiling 1 source file to C:\java\examples\typesafeEmptyCollections\build\classes[javac] Note: C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java uses unchecked or unsafe operations.[javac] Note: Recompile with -Xlint:unchecked for details. 将-Xlintunchecked指定为 javac的参数在这种情况下通过NetBeans project.properties文件中的javac.compilerargs-Xlint:unchecked 有助于获取前面列出的代码的更具体的警告消息 [javac] Compiling 1 source file to C:\java\examples\typesafeEmptyCollections\build\classes[javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:27: warning: [unchecked] unchecked conversion[javac] this.stringsList Collections.EMPTY_LIST;[javac] ^[javac] required: ListString[javac] found: List[javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:28: warning: [unchecked] unchecked conversion[javac] this.stringsSet Collections.EMPTY_SET;[javac] ^[javac] required: SetString[javac] found: Set[javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:29: warning: [unchecked] unchecked conversion[javac] this.stringsMap Collections.EMPTY_MAP; [javac] ^[javac] required: MapString,String[javac] found: Map 如果在其选项中选中了适当的提示框则NetBeans还将显示这些警告。 接下来的三个图像演示如何确保设置适当的提示以查看NetBeans中的这些警告并提供一个示例说明NetBeans如何将上面显示的代码与警告一起呈现。 幸运的是很容易利用Collections类的实用程序并以类型安全的方式访问空集合而不会导致这些javac警告和相应的NetBeans提示。 这种方法是使用Collections的方法而不是其字段 。 下一个简单的代码清单对此进行了演示。 对空集合使用集合的方法 /*** Instantiate my collections with empty versions using Collections methods.* This will avoid the javac compiler warnings alluding to unchecked conversion.*/public void instantiateWithEmptyCollectionsMethodsTypeInferred(){this.stringsList Collections.emptyList();this.stringsSet Collections.emptySet();this.stringsMap Collections.emptyMap();} 上面的代码将编译而不会发出警告并且也不会显示任何NetBeans提示。 Collections类的每个字段的Javadoc文档都没有解决为什么这些字段会出现这些警告的问题但是每个类似方法的文档都对此进行了讨论。 具体来说有关Collections.emptyList Collections.emptySet和Collections.emptyMap的文档每个状态为“不同于此方法该字段不提供类型安全性。” 对最后一个代码清单中显示的空集合使用Collections方法可提供类型安全性而无需显式指定存储在该集合中的类型因为类型是通过使用Collections方法在对已知和已经声明的实例属性的赋值中显式地推断出来的指定的元素类型。 如果无法推断类型则在使用没有显式指定类型的Collections方法时将导致编译器错误 。 下一个尝试在NetBeans中执行此操作的屏幕快照中显示了这一点。 特定的编译器错误消息是 [javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:62: error: method populateList in class Main cannot be applied to given types;[javac] populateList(Collections.emptyList());[javac] ^[javac] required: ListString[javac] found: ListObject[javac] reason: actual argument ListObject cannot be converted to ListString by method invocation conversion[javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:63: error: method populateSet in class Main cannot be applied to given types;[javac] populateSet(Collections.emptySet());[javac] ^[javac] required: SetString[javac] found: SetObject[javac] reason: actual argument SetObject cannot be converted to SetString by method invocation conversion[javac] C:\java\examples\typesafeEmptyCollections\src\dustin\examples\Main.java:64: error: method populateMap in class Main cannot be applied to given types;[javac] populateMap(Collections.emptyMap());[javac] ^[javac] required: MapString,String[javac] found: MapObject,Object[javac] reason: actual argument MapObject,Object cannot be converted to MapString,String by method invocation conversion[javac] 3 errors 通过在代码中显式指定集合元素的类型可以避免这些编译器错误并实现类型安全。 这显示在下一个代码清单中。 使用Collections的Empty方法显式指定元素类型 /*** Pass empty collections to another method for processing and specify those* empty methods using Collections methods. This will result in javac compiler* ERRORS unless the type is explicitly specified.*/public void instantiateWithEmptyCollectionsMethodsTypeSpecified(){populateList(Collections.StringemptyList());populateSet(Collections.StringemptySet());populateMap(Collections.String, StringemptyMap());} 出于相同的目的最好使用Collections类的用于获取空collection的方法而不是使用Collections的类似命名的字段因为这些方法提供了类型安全性。 这样可以更好地利用Java的静态类型系统这是诸如Effective Java这类书籍的关键主题。 一个不错的副作用是消除了混乱的警告和标记的NetBeans提示但是更重要的结果是更好更安全的代码。 参考 JCG合作伙伴 Dustin Marx在Inspired by Actual Events博客中提供的Java类型安全的空集合 。 翻译自: https://www.javacodegeeks.com/2012/11/type-safe-empty-collections-in-java.htmljava中集合判空
http://wiki.neutronadmin.com/news/326501/

相关文章:

  • 有的域名怎样做网站近期军事新闻事件
  • 有经验的佛山网站设计创业网站模板免费下载
  • 网站开发英语英语网页代码软件
  • ftp上传后没有网站新华网站建设
  • 东莞浩智建设网站公司用ps做网站导航
  • 百度做的网站 如果不做推广了 网站还保留吗国内新闻最新消息10条简短2022
  • 网站有访问量 为什么没有询盘企业微信小程序免费制作平台
  • 网站安全检测在线网站关键词优化培训
  • 安徽建设厅网站打不开大连开发区网站建设
  • 做网站按什么收费多少用php做的旅游网站
  • 开发网站网络公司有哪些购物网站创业时是如何做宣传的
  • 婴儿网站建设住栏目电子商务都是做网站的吗
  • 个人网站需要买服务器吗WordPress博客建站系统
  • 网站建设个人工作室微网站建设比较全面的是
  • 网站制作九江阿里云服务器可以用来干什么
  • 微信网站建设开发北京做网站最牛的公司
  • 给网站做接口wordpress 问答模块
  • 无锡网站公司免费广告投放平台
  • 西安做网站广告的公司888网创
  • 中卫市建设局网站 冯进强ps兼职做网站
  • 建设房地产网站中国建设银行英语网站
  • 做国外房产的网站网站虚拟主机1g
  • 宁波房产信息网官方网站广州网站建设 推广公司
  • 广扬建设集团网站chinacd.wordpress
  • 大学校园网站建设自己做的网站怎么发布视频教程
  • 投简历网站网站模糊效果
  • 解聘 人力资源网站上怎么做做试卷挣钱的网站
  • 阿里云网站怎么备案手机网站建站软件
  • 电商网站设计周志西安网站设计费用
  • 广州 定制网站3000元服务推广软文