Skip to content

Commit bb9d4f1

Browse files
committed
docs: explain public surface, delegation, and unsigned-array limit on ValueEquality
Expand the ValueEquality KDoc to answer the three questions a reader is most likely to have about it: - Why it is public with no in-tree caller: it is a deliberate, forward-looking primitive that hand-written (or later generated) value types target for their array-typed fields. - Why contentEquals is a thin wrapper over Objects.deepEquals: to pair symmetrically with contentHashCode, for which the JDK offers no Objects.deepHashCode counterpart, giving callers one contract-paired API. - That Kotlin unsigned arrays (UByteArray, etc.) are not recognized as arrays and fall through to identity-based equals/hashCode, with the asXxxArray() workaround for content semantics. Doc-only; no signature or behavior change (apiCheck unchanged).
1 parent 4163614 commit bb9d4f1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

sdk-core/src/main/kotlin/org/dexpace/sdk/core/util/ValueEquality.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ import java.util.Objects
4040
* }
4141
* ```
4242
*
43+
* No `sdk-core` type depends on these helpers today: they are published as a deliberately public,
44+
* forward-looking primitive that a hand-written value type — or, later, a DTO generator — targets
45+
* directly for its array-typed fields. The public surface is intentional, not incidental.
46+
*
47+
* Kotlin's unsigned arrays (`UByteArray`, `UShortArray`, `UIntArray`, `ULongArray`) are **not**
48+
* recognized as arrays: boxed to `Any?` they are value-class boxes, not JVM primitive arrays, so
49+
* they fall through to identity-based `equals`/`hashCode` and will not compare by content. Convert
50+
* to the signed counterpart (`asByteArray()`, `asIntArray()`, …) for any field that needs content
51+
* semantics.
52+
*
4353
* Both methods are null-safe: two `null` references are equal and hash to `0`.
4454
*/
4555
public object ValueEquality {
@@ -59,6 +69,11 @@ public object ValueEquality {
5969
* - Any other value is compared with [Any.equals].
6070
*
6171
* This is exactly the contract of `java.util.Objects.deepEquals`, to which it delegates.
72+
*
73+
* It is a thin wrapper over that JDK method, kept so it pairs symmetrically with
74+
* [contentHashCode] — for which the JDK offers no `Objects.deepHashCode` equivalent — so callers
75+
* reach one discoverable, contract-paired entry point instead of mixing `Objects.deepEquals`
76+
* with a hand-rolled hash.
6277
*/
6378
@JvmStatic
6479
public fun contentEquals(

0 commit comments

Comments
 (0)