Skip to content

specify when fields are marked 'final' in bytecode #3226

Open
@scabug

Description

@scabug

The Java Memory Model (since 1.5) treats final fields differently to non-final fields. In particular, provided the this reference doesn't escape during construction, writes to final fields in the constructor are guaranteed to be visible on other threads even if the object is made available to the other thread via a data race. (Writes to non-final fields aren't guaranteed to be visible, so if you improperly publish them, another thread could see them in a partially constructed state.)

As far as I can tell there isn't any documentation on how/if the Scala compiler creates final (rather than non-final) backing fields for classes/traits/objects. I've looked through the language specification and searched the web but can't find any definitive answers.

It looks like values are currently final fields (since ticket #201), but think it would be good for this to be explicitly documented.

See http://stackoverflow.com/questions/2462287 for background to this question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions