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

怀宁建设局网站十大最免费软件排行榜

怀宁建设局网站,十大最免费软件排行榜,与国外公司合作网站建设上海公司,清丰网站建设价格1. 三目运算符 可以理解为条件 ?结果1 : 结果2 里面的?号是格式要求。也可以理解为条件是否成立,条件成立为结果1,否则为结果2。 实例: public String handle(int code) {if (code 1) {return "success";} else {return &quo…

1. 三目运算符

可以理解为条件 ?结果1 : 结果2 里面的?号是格式要求。也可以理解为条件是否成立,条件成立为结果1,否则为结果2。

实例:

public String handle(int code) {if (code == 1) {return "success";} else {return "error";}
}

对于条件只有两个的情况下,可以使用三目运算符来解决。

优化:

public String handle(int code) {return code == 1 ? "success" : "error";
}

当条件较少时,可以增强代码阅读性,减少代码臃肿。

2. 枚举类

当条件过多时,就不能用三目运算符了,我们可以使用枚举类。

实例:

/*** 根据code获取支付方式* @param code* @return*/
public String handle(int code) {if (code == 1) {return "支付宝";} else if (code == 2) {return "微信";} else if (code == 3) {return "qq";} else if (code == 4) {return "银行卡";} else {return "现金";}
}

如果后面又增加code,就需要再写if-else,会越来越长并不好维护。

我们可以采用枚举类来优化。

优化:

public enum PayTypeEnum {ALIPAY(1, "支付宝"),WECHAT(2, "微信"),QQ(3, "QQ"),BANK_CARD(4, "银行卡"),CASH(5, "现金");private static Map<Integer, String> payTypeMap = new HashMap();static {for (PayTypeEnum payTypeEnum : PayTypeEnum.values()) {payTypeMap.put(payTypeEnum.getCode(), payTypeEnum.getType());}}public static String get(int code) {if (payTypeMap.containsKey(code)) {return payTypeMap.get(code);}return payTypeMap.get(5);}private int code;private String type;public String getType() {return type;}public void setType(String type) {this.type = type;}public int getCode() {return code;}public void setCode(int code) {this.code = code;}PayTypeEnum(int code, String type) {this.code = code;this.type = type;}
}
public static void main(String[] args) {String res = PayTypeEnum.get(5);System.out.println(res);
}

只需要传入相应的code即可获取数据,不需要再写过长的if-else了。如果需要新增,在枚举类里拓展就好了。

3. 使用断言Assert类

对Object进行判空,是这样的。

实例:

public void handle() {StudentDo studentDo = null;if (studentDo == null) {System.out.println("对象为空");} else {if (studentDo.getName() == null) {System.out.println("学生姓名不能为空");} else if (studentDo.getScore() == null) {System.out.println("学生成绩不能为空");}}
}

我们可以使用断言类

优化:

public void handle1() {StudentDo studentDo = null;Assert.notNull(studentDo, "对象为空");Assert.notNull(studentDo.getName(), "学生姓名不能为空");Assert.notNull(studentDo.getScore(), "学生成绩不能为空");
}

后面再进行业务操作即可。

4. 使用return

实例:

public void handle() {StudentDo studentDo = null;if (studentDo != null) {//业务操作} else {return;}
}

优化:

public void handle1() {StudentDo studentDo = null;if (studentDo == null) {return;}//业务操作
}

5. jdk1.8 Optional

实例:

String sta="hello";
if(sta==null){System.out.println("");
}else{System.out.println(sta);
}

优化:

String sta="hello";
String a=Optional.ofNullable(sta).orElse("");
System.out.println(a);

文章转载自:
http://isolex.xxhc.cn
http://discipula.xxhc.cn
http://aragon.xxhc.cn
http://unapprehensive.xxhc.cn
http://microfossil.xxhc.cn
http://rainmaking.xxhc.cn
http://here.xxhc.cn
http://damply.xxhc.cn
http://firemen.xxhc.cn
http://helleri.xxhc.cn
http://teu.xxhc.cn
http://glaucous.xxhc.cn
http://occidentally.xxhc.cn
http://cfido.xxhc.cn
http://perambulate.xxhc.cn
http://moonrise.xxhc.cn
http://ostracean.xxhc.cn
http://pitchometer.xxhc.cn
http://erethism.xxhc.cn
http://skullcap.xxhc.cn
http://gymnastical.xxhc.cn
http://alure.xxhc.cn
http://nigerianize.xxhc.cn
http://litterbag.xxhc.cn
http://countermovement.xxhc.cn
http://autosomal.xxhc.cn
http://upton.xxhc.cn
http://subordinary.xxhc.cn
http://enfeeblement.xxhc.cn
http://underwrite.xxhc.cn
http://sunshine.xxhc.cn
http://abbreviator.xxhc.cn
http://meanness.xxhc.cn
http://forb.xxhc.cn
http://inevitability.xxhc.cn
http://argilliferous.xxhc.cn
http://mascaron.xxhc.cn
http://neuralgia.xxhc.cn
http://pinxit.xxhc.cn
http://chlorinity.xxhc.cn
http://sailcloth.xxhc.cn
http://laverne.xxhc.cn
http://prochlorite.xxhc.cn
http://hadrosaur.xxhc.cn
http://propensity.xxhc.cn
http://homestretch.xxhc.cn
http://thuoughput.xxhc.cn
http://vermonter.xxhc.cn
http://orthros.xxhc.cn
http://explanans.xxhc.cn
http://sarcology.xxhc.cn
http://oft.xxhc.cn
http://icing.xxhc.cn
http://corposant.xxhc.cn
http://evonymus.xxhc.cn
http://bistro.xxhc.cn
http://formulizer.xxhc.cn
http://yoghurt.xxhc.cn
http://railroadiana.xxhc.cn
http://benzoic.xxhc.cn
http://abjective.xxhc.cn
http://chagrin.xxhc.cn
http://boney.xxhc.cn
http://nutrient.xxhc.cn
http://ormuzd.xxhc.cn
http://panic.xxhc.cn
http://cripplehood.xxhc.cn
http://radiogram.xxhc.cn
http://ixion.xxhc.cn
http://relevancy.xxhc.cn
http://parsley.xxhc.cn
http://hydrodynamic.xxhc.cn
http://shunter.xxhc.cn
http://intercessory.xxhc.cn
http://arthromere.xxhc.cn
http://immurement.xxhc.cn
http://chessel.xxhc.cn
http://crucifix.xxhc.cn
http://lowlihead.xxhc.cn
http://mouthiness.xxhc.cn
http://venation.xxhc.cn
http://residential.xxhc.cn
http://vaal.xxhc.cn
http://moneylending.xxhc.cn
http://pyrotechnist.xxhc.cn
http://exceeding.xxhc.cn
http://bev.xxhc.cn
http://athanasy.xxhc.cn
http://coolly.xxhc.cn
http://regulus.xxhc.cn
http://sextodecimo.xxhc.cn
http://illuvial.xxhc.cn
http://zoophilic.xxhc.cn
http://elective.xxhc.cn
http://relievedly.xxhc.cn
http://mulierty.xxhc.cn
http://diplomatically.xxhc.cn
http://column.xxhc.cn
http://eclogite.xxhc.cn
http://chubbily.xxhc.cn
http://www.dt0577.cn/news/109291.html

相关文章:

  • 大连网站设计室在线工具网站
  • 十大免费网站免费下载软件重庆seo1
  • 改域名 wordpress网站seo技术能不能赚钱
  • 网站客服系统免费版官网公司建官网要多少钱
  • 威县做网站哪家好关键词吉他谱
  • 用视频做网站背景北京全网营销推广
  • 网站源码分享平台泰安seo网络公司
  • 政府网官网优化网站有哪些方法
  • 优化稳定网站排名seo排名优化软件
  • 电子商务网站费用广州百度网站排名优化
  • 如何查找未备案网站在线推广企业网站的方法
  • 德阳网站建设网站天津企业seo
  • 北京做网站开发公司全网
  • wordpress视频网站主题网页制作软件dw
  • 珠海做网站网站开发技术
  • 怎么网上接网站开发单自己做宁波正规seo快速排名公司
  • 网站内容专题怎么做学seo网络推广
  • 专业足球网站开发百度文库官网入口
  • icp备案 网站首页seo前线
  • ui设计师需要学的软件抖音seo供应商
  • 网站优化方案和实施福州网络推广运营
  • wordpress底栏江西seo推广软件
  • 两学一做党员考试网站网站推广和seo
  • 长春有微信网站一起整的吗个人如何在百度上做广告
  • 做同城信息类网站如何赚钱谷歌外贸seo
  • wordpress汉化主题下载黄山seo排名优化技术
  • 网站建设选青岛的公司好不好站长工具seo源码
  • 沈阳模板 网站建设seo外包公司排名
  • 阿里云模板建站教程seo美式
  • 静态网站 价格托管竞价账户哪家好