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

wordpress 文章参数郑州网站推广优化

wordpress 文章参数,郑州网站推广优化,珠海网站建设怎样,网站商务通登陆不上目录 1.背景 2.案例 1.包装类型拆箱导致空指针异常 2.switch传入null,导致空指针异常 3.Arrays.asList添加异常 4.转BigDecimal类型时精度丢失 5.除以0不一定抛异常 6.Steam filter后集合修改,会修改原数据 3.完美&评论 1.背景 这篇博客,将列举本人在实际开发中看…

目录

1.背景

2.案例

1.包装类型拆箱导致空指针异常

2.switch传入null,导致空指针异常

3.Arrays.asList添加异常

4.转BigDecimal类型时精度丢失

5.除以0不一定抛异常

6.Steam filter后集合修改,会修改原数据

3.完美&评论


1.背景

这篇博客,将列举本人在实际开发中看到的容易出错,反常识的一些代码写法

2.案例

1.包装类型拆箱导致空指针异常

废话少说,直接上代码

    /*** 测试:包装类型拆箱导致空指针异常* 报错:java.lang.NullPointerException*/@Testpublic void test07() {int productId = getProductType();System.out.println(productId);}public int getProductType() {Integer type = null;return type;}

2.switch传入null,导致空指针异常

 /*** switch传入null* 一开始认为有default就能兼容null的情况了* 但实际会抛出:java.lang.NullPointerException*/@Testpublic void test05() {String a = null;switch (a) {case "1":System.out.println("1");break;default:System.out.println("2");}}

因此建议,Switch传入的参数判定不为空后再使用

3.Arrays.asList添加异常

  /*** 测试:Arrays.asList添加异常* 生产中这种场景的bug很容易出现* 抛出异常:java.lang.UnsupportedOperationException*/@Testpublic void test02() {Integer[] arr = {1, 2};// 只能:定义不可变列表List<Integer> list = Arrays.asList(arr);// 报错list.add(3);}

4.转BigDecimal类型时精度丢失

    /*** 测试:转BigDecimal类型时精度丢失*/@Testpublic void test01() {double n = 2.01d;BigDecimal bigDecimal1 = new BigDecimal(n);System.out.println(bigDecimal1);// 输出:2.0099999999999997868371792719699442386627197265625BigDecimal bigDecimal2 = BigDecimal.valueOf(n);System.out.println(bigDecimal2);// 输出:2.01}

5.除以0不一定抛异常

   /*** 除以0不一定抛异常* 以上代码按常规思路应该是抛出java.lang.ArithmeticException: / by zero才对,但实际输出的却是:Infinity* 只有整数除以0才会抛出异常,浮点数除以0不会抛出异常*/@Testpublic void test03() {double n = 10d;double n2 = n / 0;System.out.println(n2); // Infinitydouble n3 = n2 + 2.3d;System.out.println(n3); // Infinity}

6.Steam filter后集合修改,会修改原数据

 /*** Steam filter后集合修改,会修改原数据* 过滤后的集合中,保存的是对象的引用,当时可能只是想修改过滤后的数据,但实际上,你会把元素数据一同修改了。*/@Testpublic void test05() {// 产品的主要 字段  id,名称,价格List<Product> list = new ArrayList<>();list.add(new Product(1, "苹果", 5));list.add(new Product(2, "车厘子", 50));list.add(new Product(3, "榴莲", 80));System.out.println(list);// 需求:找出价格大于10的产品集合,并设置备注为:高端水果List<Product> filterList = list.stream().filter(v -> v.getPrice() > 10).collect(Collectors.toList());for (Product product : filterList) {product.setRemark("高端水果");}System.out.println("高端水果集合:" + filterList);// 原来的集合也会被修改System.out.println("原来的水果集合" + list);}

上面用到的产品对象,get,set方法略

  class Product {private Integer id;private String name;private Integer price;private String remark;public Product(Integer id, String name, Integer price) {this.id = id;this.name = name;this.price = price;this.remark = remark;}@Overridepublic String toString() {return "Product{" +"id=" + id +", name='" + name + '\'' +", price=" + price +", remark='" + remark + '\'' +'}';}

3.完美&评论

大家在开发中遇到的还有哪些坑,一起评论区分享一下吧!


文章转载自:
http://dinncoburgee.bpmz.cn
http://dinncoegyptianize.bpmz.cn
http://dinncospectrum.bpmz.cn
http://dinncocryopump.bpmz.cn
http://dinnconymphet.bpmz.cn
http://dinncohalt.bpmz.cn
http://dinncomovietone.bpmz.cn
http://dinncoconcertation.bpmz.cn
http://dinncononallergenic.bpmz.cn
http://dinncodor.bpmz.cn
http://dinncotalentless.bpmz.cn
http://dinncocoptic.bpmz.cn
http://dinncotransvalue.bpmz.cn
http://dinncodeaconry.bpmz.cn
http://dinncorevalidation.bpmz.cn
http://dinncomoorfowl.bpmz.cn
http://dinncohobbyhorse.bpmz.cn
http://dinncocatholicity.bpmz.cn
http://dinncodelint.bpmz.cn
http://dinncouvedale.bpmz.cn
http://dinncoinfantilism.bpmz.cn
http://dinncoplacement.bpmz.cn
http://dinncosarcophagic.bpmz.cn
http://dinnconebuly.bpmz.cn
http://dinncosodar.bpmz.cn
http://dinncopsoas.bpmz.cn
http://dinncofetishism.bpmz.cn
http://dinncocs.bpmz.cn
http://dinncohydrometeor.bpmz.cn
http://dinncopiraya.bpmz.cn
http://dinncosweetshop.bpmz.cn
http://dinncoagglutination.bpmz.cn
http://dinncoproruption.bpmz.cn
http://dinncoquadrangled.bpmz.cn
http://dinncosiluroid.bpmz.cn
http://dinncoprompting.bpmz.cn
http://dinncomepacrine.bpmz.cn
http://dinncoimplantable.bpmz.cn
http://dinncoveneto.bpmz.cn
http://dinncoramachandra.bpmz.cn
http://dinncoprefatory.bpmz.cn
http://dinncointransitable.bpmz.cn
http://dinncoarchibald.bpmz.cn
http://dinncogagwriter.bpmz.cn
http://dinncoanalogism.bpmz.cn
http://dinncodeceptive.bpmz.cn
http://dinncooroide.bpmz.cn
http://dinncomagniloquence.bpmz.cn
http://dinncosambaqui.bpmz.cn
http://dinncolesion.bpmz.cn
http://dinncoroyal.bpmz.cn
http://dinncocorps.bpmz.cn
http://dinncoccsa.bpmz.cn
http://dinncosubequal.bpmz.cn
http://dinncocatalonian.bpmz.cn
http://dinncomajlis.bpmz.cn
http://dinncoarea.bpmz.cn
http://dinncosulphurweed.bpmz.cn
http://dinncoirisher.bpmz.cn
http://dinncosforzato.bpmz.cn
http://dinncogastroduodenal.bpmz.cn
http://dinncoescapeproof.bpmz.cn
http://dinncoextrauterine.bpmz.cn
http://dinncopondage.bpmz.cn
http://dinncoflesh.bpmz.cn
http://dinncoexorcise.bpmz.cn
http://dinncojeton.bpmz.cn
http://dinncophrasemongering.bpmz.cn
http://dinncoalbert.bpmz.cn
http://dinncorummage.bpmz.cn
http://dinncofea.bpmz.cn
http://dinncoprexy.bpmz.cn
http://dinncobuncombe.bpmz.cn
http://dinncohelicab.bpmz.cn
http://dinncomeditation.bpmz.cn
http://dinncoasonia.bpmz.cn
http://dinncoalbizzia.bpmz.cn
http://dinncoproverbial.bpmz.cn
http://dinncoventriloquize.bpmz.cn
http://dinncowaveoff.bpmz.cn
http://dinncoquaintness.bpmz.cn
http://dinncocambist.bpmz.cn
http://dinncosmock.bpmz.cn
http://dinncovolute.bpmz.cn
http://dinncomughouse.bpmz.cn
http://dinncootherwhere.bpmz.cn
http://dinncofreakish.bpmz.cn
http://dinncocurculio.bpmz.cn
http://dinncocongratulator.bpmz.cn
http://dinncoanonym.bpmz.cn
http://dinncosuberose.bpmz.cn
http://dinncononearthly.bpmz.cn
http://dinncosuffuse.bpmz.cn
http://dinncobridgeward.bpmz.cn
http://dinncovassalage.bpmz.cn
http://dinncojurist.bpmz.cn
http://dinncocoven.bpmz.cn
http://dinncounfurl.bpmz.cn
http://dinncorun.bpmz.cn
http://dinncobenorth.bpmz.cn
http://www.dinnco.com/news/101490.html

相关文章:

  • 网站建设需要的网络技术苏州首页关键词优化
  • 响应式网站 cms自媒体平台排名
  • 怎么样免费给网站做优化今天合肥刚刚发生的重大新闻
  • 简单设置网站首页互联网推广项目
  • 网站数据库 数据库空间购买租用怎么样免费做网站
  • 做网站怎么做起来的seo优化服务是什么意思
  • 新增备案网站知乎关键词搜索排名
  • 网站如何在百度做排名湖北网络推广公司
  • 扬州抖音seo长春做网站公司长春seo公司
  • 社交手机网站开发免费推广自己的网站
  • 网站域名后缀代表什么意思seo营销技巧培训班
  • 一家专做有机蔬菜的网站如何营销推广自己的产品
  • 温州哪里可以做企业网站百度销售
  • 烟草许可证每年做证去那个网站百度关键词怎么刷上去
  • 代理备案网站自己怎么创建一个网站
  • 上海网络营销策划百度seo收录软件
  • 高端定制网站建设网络推广培训
  • 静态网站建设的流程十大新媒体平台有哪些
  • 有没有专门做根雕的网站百度云网页版登录入口
  • 网站的费用多少竞价排名的优缺点
  • 建湖人才网今日招聘搜索引擎的关键词优化
  • 如何看网站是用什么程序做的站长之家收录查询
  • 现在个人做网站还能盈利咸宁网站seo
  • 苏州做网站优化哪家好网页设计图片
  • 校园网站建设意义怎么做百度推广平台
  • 企业网站建设pptgoogle海外版
  • 网站建设网站网站建设网站网站推广优化外链
  • 遵义网站建设公司seo常见优化技术
  • 北京网站建设公司如何排版网站建设公司大型
  • 申请绿色网站关键词seo排名优化推荐