Skip to content

Should we provide a way to query the status of late variables? #324

@leafpetersen

Description

@leafpetersen

As proposed, the only way to query the state of a late initialized variable to see if it has been written would be to try to read it, and catch the resulting error. We explicitly discourage catching errors, so this seems non-ideal. Should we provide this functionality? And if so, how do we expose it?

For comparison, Kotlin provides a way to do this via reflection.

If we do provide this, then what is the right behavior for it on late int x = 3 + 3? Is this variable considered initialized before the first read/write (since it has an initializer)? Or is it considered uninitialized since the initializer has not yet been run (and may in principle never complete with a value and cause the variable to actually be initialized)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    nnbdNNBD related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions