andym
07/29/2023, 4:25 AMProperty "xxx" is never used
• Is it normal to use @Suppress("unused")
for every value class?
• And why does the linter not recognize this special case for a value class?Chris Lee
07/29/2023, 6:02 AMandym
07/29/2023, 5:34 PM@JvmInline
value class Id(private val value: String)
and for each one, I getChris Lee
07/29/2023, 5:35 PMprivate
, implying you intend to use it within the class (you don’t, hence the warning). Remove private
or use the property inside the class.andym
07/29/2023, 5:40 PMChris Lee
07/29/2023, 5:42 PMval
) or incomplete (should show use of the prop).Chris Lee
07/29/2023, 5:46 PM@JvmInline
public value class Password(private val value: String) {
override fun toString(): String = value
}
@JvmInline
public value class Id(private val value: String) {
override fun toString(): String {
return "Id(value='$value')"
}
public fun asString() : String = value
}
Sam
07/30/2023, 6:57 AMKlitos Kyriacou
07/31/2023, 8:55 AM@JvmInline
value class Password(private val value: String) {
override fun toString() = "***"
fun asPlaintextString() = value
}
That way when you have to pass the actual password text (e.g. to an API) the class forces you to realise that you're passing a password in plain view.
Credit for the idea: https://void2unit.onrender.com/post/inline+password/