4 ms·
My solution is to convert to Kotlin, I can't stand working on Java anymore: customer?.order?.lineItemList?.forEach { item -> val currency = item?.product?.
by Jenkins2000 4y ago
My solution is to convert to Kotlin, I can't stand working on Java anymore:
customer?.order?.lineItemList?.forEach { item ->
val currency = item?.product?.price?.currency
- commandlinefan 4y agoIf I'm understanding this correctly, it's still a problem: if the product's price element or the order's line item list is null, for example, that shouldn't just be silently ignored. The transaction should fail, loudly and visibly (like with an exception) so that the root cause of the invalid data can be examined. The way most programmers code it is to just ignore the bad data and potentially ship an item for free, or without charging tax, or charge the customer but not ship the item, etc. etc. This is why so many software development organizations have huge QA departments.
- Jenkins2000 4y agoI still write null checks if needed but for deeply nested objects, it comes down to only checking for null at the end of the chain instead of in Java where you have null checks each step of the way.
- oweiler 4y agoYou can chain Optional exactly the same as Kotlin but without the syntay suger ofc.