[NSWI080] Task 2 - Java - Accessing (non existing) optional field

Petr Tuma petr.tuma at d3s.mff.cuni.cz
Sun Apr 3 18:41:55 CEST 2022


Hi,

you should first check whether the field is set with `isSet`. Calling the getter without first checking for presence returns `0` for integers, `0.0` for floats, `null` for strings etc.

Petr


On 03/04/2022 01:02, Matúš Maďar wrote:
> Hello all.
> I haven't found anything in documentation so I'd like to ask. Did anyone encounter and can explain, what is the expected behaviour in Java, when you try to access optional field in service? E.g. if ItemA doesn't have fieldZ defined; will it throw some exception or will it just return default value of the type of field?
> Thanks!
> 
> _______________________________________________
> NSWI080 mailing list
> NSWI080 at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/nswi080


More information about the NSWI080 mailing list