Why do inline classes do implement toString using...
# stdlib
h
Why do inline classes do implement toString using the wrapper and not just the value. E.g. in
Copy code
@JvmInline
value class Area(val name: String)
"Area(name=foo)" instead of "foo". Aren't they meant to provide just some typesafe wrapper while inline the value whenever possible?
a
It does still inline the value, value classes generate a static toString/hashCode/equals which takes the wrapped value as a parameter.
Looks like this:
n
I would agree that a return value.toString() might be a better choice for value classes
👍 2
2
e
I disagree. even if it uses the same underlying representation, a value class is a separate type
👍🏻 1
👍 5
👍🏾 1
m
That is why in Python there is separate
str
and
repr
😛 https://www.geeksforgeeks.org/str-vs-repr-in-python/