Skip to content

Hint to me when I have nullable fields in an object #57173

Closed
@sethladd

Description

@sethladd

The following construct should be avoided:

class Thing {
  double x;
  double y;
  double z;

  Thing(this.x, this.y, this.z);
  Thing.empty() {}
}

Issues are:

  • x, y, and z could become null if Thing is constructed via empty().

The VM has a hard time optimizing fields that could be double or null. dart2js has a hard time optimizing field access that could be null.

Of course, I could set x,y,z to final. Or, I could eliminate empty() constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions