WillBecomeValue
Marks a regular class that has value semantics and will be converted to a value class in the future to preventively discourage its referential usages.
A class annotated with WillBecomeValue:
Must not be relied upon for identity. Reference equality (
===), identity hash codes, and synchronization on instances are considered undefined behavior.Must be shallow-immutable. Mutating state through shared references undermines the value semantics the annotation promises.
Is a candidate for future migration to a
value class, so the annotation is expected to be dropped once the migration is complete.
In future Kotlin releases, the compiler is going to apply every declaration check of a value class to the annotated class, reporting errors just as it would for a real value class. Identity-sensitive usages, however, are only going to be reported as warnings outside of the annotated class itself, which gives downstream users time to migrate before the class actually becomes a value class.
A final annotated class also is going to have to override equals, hashCode and toString, because the identity-based implementations inherited from Any would silently turn structural once the class becomes a value class. An annotated object is going to override only toString: having a single instance, it already compares and hashes the same way a value object would.
The annotation is going to be applicable to final classes, to abstract/sealed classes intended as base types, and to object declarations. It is not going to be applicable to value classes, interfaces, enums, or open classes.