EqualityBound

annotation class EqualityBound(val bound: KClass<*>)(source)

This annotation can only be applied to a value parameter of an equals operator. Annotating any other parameters with it results in a compilation error.

Expresses that equals can only return true if its left-hand side is subtype of bound's argument. In particular,

  • Body of such equals is implicitly modified with preliminary guard checking this subtype relation;

  • On use-sites, compilation error is reported if left-hand side is definitely incompatible with bound's argument.

Please note that this annotation is experimental and can only be used when the corresponding language feature is enabled.

Since Kotlin

2.5

Properties

Link copied to clipboard
val bound: KClass<*>
Since Kotlin 2.5