Johann Pardanaud
10/18/2024, 2:09 PMcopy
method of a data class has the same visibility as the primary constructor.
However, the library guidelines still instructs to avoid data classes in public API.
I have a class really similar to a data class. I went for a basic class because I wanted all the features of a data class, except my constructor is internal and I didn't want to expose a copy
method.
Can I swap it for a data class? I'm aware it will expose componentX
methods but I already provide them (code in thread)Johann Pardanaud
10/18/2024, 2:10 PMpublic class ConstraintViolation internal constructor(public val message: String, public val path: Path) {
public operator fun component1(): String = message
public operator fun component2(): Path = path
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
other as ConstraintViolation
if (message != other.message) return false
return path == other.path
}
override fun hashCode(): Int {
var result = message.hashCode()
result = 31 * result + path.hashCode()
return result
}
override fun toString(): String = "ConstraintViolation(message='$message', path=$path)"
}
Chris Lee
10/18/2024, 4:13 PMJohann Pardanaud
10/18/2024, 4:18 PMcomponentX
methods, can't I just use data classes?bobko
10/22/2024, 2:43 PMcomponentX
Johann Pardanaud
10/22/2024, 2:44 PMJohann Pardanaud
10/22/2024, 2:45 PM