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 8

Generics and the type system interview questions

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

7 questions: 3 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

    In Dart, is <int>[] a List<num>, and could a Java program ask the same question?

    Answered in the lesson Generics: classes, methods and bounds

  2. Fresher

    What does the declaration List tags = ['new', 'sale']; really declare?

    Answered in the lesson Generics: classes, methods and bounds

  3. Fresher

    What does it mean that Dart's type system is sound, and which checks still happen while a program runs?

    Answered in the lesson The Dart type system: dynamic, Object?, Never

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 service turns JSON into model objects through a registry: register<T>(fromJson) stores a decoder, and decode<T>(body) looks one up for T. Explain why this works in Dart but needs another shape in Java, how you key the registry, and what decode<Object> or an unregistered type should do.

    What it tests
    Knowing that Dart keeps type arguments at run time, so T itself can key a map, why erased Java code hands over a Class object instead, and how a lookup by exact type behaves for supertypes and nullable types.
    First step
    Start from what decode<T> knows while it runs: in Dart the T of each call is a real Type value, so the registry can be a map from Type to decoder, filled by register<T> and read by decode<T>. Then ask what an exact Type lookup does for Object, for a subtype and for T?.
    Follow-ups

    From the lesson Generics: classes, methods and bounds

    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 4 minutes
  2. Mid to senior

    A 300-file Dart app predates its lint setup and has about 400 raw List and Map annotations. The team wants no_raw_types to fail CI. Plan the rollout so that CI stays green while the fixes land, explain how you choose each missing type argument, and say where a wrong choice will show up.

    What it tests
    Knowing that no_raw_types reports infos until its severity is raised, that dart fix offers no fix for it, how ignore comments stage a rollout, and that a wrong type argument turns into compile errors or run-time TypeErrors.
    First step
    Measure before changing anything: turn the lint on at its default info severity, run dart analyze to count the raw types file by file, and note that dart analyze still exits 0 at that point. The count and the file list become the plan.
    Follow-ups

    From the lesson Generics: classes, methods and bounds

    Model answer, Pro.

    In the answer:

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

    An app reads API responses as Map<String, dynamic> in about 40 widgets. A backend release sends some numbers as strings, such as "qty": "2", and three screens crash far from the network code. Design a decoding layer where a format change fails in one place, naming the field, and decide what to do with "2".

    What it tests
    Knowing that reads from dynamic are implicit casts checked at run time, how to validate JSON once at the boundary into typed classes, how to report the failing field, and when tolerating a changed format is right.
    First step
    Find where the casts happen: every final int x = json['...'] in a widget is an unchecked promise. Move them into one fromJson per model, called right after jsonDecode, so the widgets only ever see typed objects and the first wrong value stops in that one function.
    Follow-ups

    From the lesson The Dart type system: dynamic, Object?, Never

    Model answer, Pro.

    In the answer:

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

    A settings library exposes dynamic setting(String key), and callers write setting('timeout') + 5 and setting('hosts').first. For the next major version you want it to return Object? instead. What breaks at the call sites, how do callers adapt, and what typed API would you offer next to it?

    What it tests
    Knowing that Object? forbids unchecked member use where dynamic allowed it, how callers migrate with type tests or casts, and how a generic accessor such as T setting<T>(String key) can check the value at run time.
    First step
    List what callers do with the result today: arithmetic, collection access, string calls. Each of those compiles on dynamic and becomes a compile error on Object?, which is the point: every place that assumed a type now has to say which type it expects.
    Follow-ups

    From the lesson The Dart type system: dynamic, Object?, Never

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 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.