看到源代码里有如下程序段,感觉看着不舒服,但又不知道该如何重构,求助各位:
- Java code
if (entity != null && entity.getDetail() != null && entity.getDetail().getPrincipals() != null && entity.getDetail().getPrincipals().size() >= 1) { PrincipalEntity principalEntity = (PrincipalEntity) entity.getDetail().getPrincipals().get(0); if (principalEntity != null && principalEntity.getInfo() != null) { return principalEntity.getInfo(); } }
------解决方案--------------------
没法重构了,最多也是碰到不对就 return
- Java code
if (entity == null) { return;}if (entity.getDetail() == null) { return;}if (entity.getDetail().getPrincipals() == null) { return;}if (entity.getDetail().getPrincipals().size() < 1) { return;}...
------解决方案--------------------