Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Dart (3.13) Module 4

Sound null safety interview questions

Interview questions on sound null safety: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

6 questions: 2 warm-ups and 4 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What does the ! operator do, and why is it called a code smell?

    Answered in the lesson Sound null safety: nullable types and operators

  2. Fresher

    When should you prefer a nullable type over a late variable?

    Answered in the lesson Type promotion, late and definite assignment

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A screen crashes with "Null check operator used on a null value" for some users but not others. The code reads user profile fields with ! throughout, such as user.phone! and user.address!.city!. Walk through how you would find the crash and remove the ! operators without changing behaviour for users whose fields are set.

    What it tests
    Knowing that ! throws only when a field is actually null, how to reproduce with a sparse profile, and the safe replacements: ??, promotion, ?., if-case and null-aware elements.
    First step
    Reproduce with a user whose optional fields are null, then read the stack trace to the exact ! that threw. The ones that never fire are on fields that happen to be always set for the users you tested.
    Follow-ups

    From the lesson Sound null safety: nullable types and operators

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A teammate used a language whose nullability was only a warning and asks what "sound" buys that is worth the extra ? and ! in the code. Explain what soundness guarantees, one thing it lets the compiler do, and one class of bug it removes, with a concrete example.

    What it tests
    Knowing that soundness means a non-nullable type is never null at run time, that it lets the compiler elide null checks, and that it turns a class of null-dereference crashes into compile errors.
    First step
    Contrast a guarantee with a warning: a warning can be ignored and the null still arrives, while a sound type system proves the null cannot be there. Then name what each side can and cannot rely on.
    Follow-ups

    From the lesson Sound null safety: nullable types and operators

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A class has a public field String? status, and a method checks if (status != null) then calls status.trim(). The compiler reports that status cannot be promoted. Explain why a local variable would promote but this field does not, and give the fixes you would choose between.

    What it tests
    Knowing that fields can change or be overridden by a getter so the checked value may differ from the used value, and the fixes: a local copy, a private final field (promotable since 3.2), or an if-case.
    First step
    Ask what could change status between the check and the call. A local cannot change underneath you; a public field could be reassigned, or a subclass could make it a getter that returns a new value each read.
    Follow-ups

    From the lesson Type promotion, late and definite assignment

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid to senior

    A Session class declares late User user; and late String token; so the rest of the code can use them without null checks. Logged-out sessions never set them, and the app crashes with LateInitializationError when a guest opens a profile screen. Explain the trade-off the team made with late, and how you would redesign Session.

    What it tests
    Knowing that late trades a compile-time guarantee for a run-time one, that a legitimately-absent value should be nullable, and how to split always-present from maybe-absent fields.
    First step
    For each late field ask whether a logged-out session can exist without it. If yes, late is the wrong tool: the absence is legitimate and belongs in the type as nullable.
    Follow-ups

    From the lesson Type promotion, late and definite assignment

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Dart (3.13) interview questions · The Dart (3.13) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.