vendredi 5 mars 2021

Sequence of or and and in if block not working correctly

 CCMT c = new CCMT();
 c.ccd = null;
Optional<String> cType = Optional.ofNullable(ccmtRequest).map(CCMT::getCcd).map(MOEH::getDestCtry);         

System.out.println(cType.isPresent()); // false
    
if(cType.isPresent() && cType.get().equalsIgnoreCase("CCMT") || cType.get().equalsIgnoreCase("CCWC")) {
  System.out.println("wfegr");
}

ERROR: Exception NoSuchElementException

Why cType.get() statement is being executed even though first condition is false itself?

Aucun commentaire:

Enregistrer un commentaire