Check if all fields in a record have been set.
← Operators and Expressions · Ref: Q1087
Check if a record is set with the ? operator:
if full? stdout.println("set")
'default operator ?' uses ALL-field (flattened-aggregate) semantics — it is true only if EVERY field is set, own and inherited. A single unset field makes the whole object unset. Use 'override operator ?' if you need different logic.
See Q1089 for custom override operator ?.
Example
defines module qa.operators.checkrecordfullyset defines class AppConfig dbHost <- String() dbPort <- Integer() apiKey <- String() AppConfig() -> dbHost as String dbPort as Integer apiKey as String this.dbHost :=: dbHost this.dbPort :=: dbPort this.apiKey :=: apiKey AppConfig() -> dbHost as String this.dbHost :=: dbHost default operator defines program CheckRecordFullySetDemo() stdout <- Stdout() //Fully set config full <- AppConfig("db.prod", 5432, "secret-key-123") stdout.println(`Full config set?: ${full?}`) //Partially set — only dbHost provided partial <- AppConfig("db.dev") stdout.println(`Partial config set?: ${partial?}`) //Empty — no fields set blank <- AppConfig() stdout.println(`Empty config set?: ${blank?}`)
Common mistakes
E01073 — EK9 has no 'null'; use the '?' operator to test whether an object is set. See ek9 -h E01073 for details.
Incorrect:
${full != null}
Correct:
${full?}
Other ways to ask this
- Test whether an object is fully initialised using ?
- Determine if a record has any unset fields
- In Java I'd check each field for null. How do I check if an EK9 object is set?
- I need to verify that a config object has all required values before using it
Coming from another language?
Java: manual null checks per field, or Bean Validation @NotNull. Python: all(v is not None for v in vars(obj).values()). EK9: ? operator with default (all-field) or custom (override) semantics.
Keywords: validate, isSet, ?, check, operator, initialised, set