Hello! I am sorry if this not the correct place to...
# getting-started
t
Hello! I am sorry if this not the correct place to ask this kind of things, but i ran into this error:
e: Platform declaration clash: The following declarations have the same JVM signature (getPassword()Ljava/lang/String;):
fun `<get-password>`(): String defined in com.test.model.User
fun getPassword(): String? defined in com.test.model.User
What is the most common approach for this? Is it something recurring using Spring Boot with Kotlin?
Copy code
@Entity
@Table(name = "user")
class User(
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    var id: Long? = null,

    @NotEmpty(message = "First name cannot be empty.")
    @Column(name = "first_name")
    var firstName: String,

    @NotEmpty(message = "Last name cannot be empty.")
    @Column(name = "last_name")
    var lastName: String,

    @NotEmpty(message = "Email cannot be empty.")
    @Email(message = "Invalid email.")
    var email: String,

    @NotEmpty(message = "Password cannot be empty.")
    var password: String,

    @Enumerated(value = EnumType.STRING)
    var role: Role,
) : UserDetails {
    override fun getAuthorities(): Collection<GrantedAuthority?>? {
        return mutableListOf()
    }

    override fun getPassword(): String? {
        return password
    }

    override fun getUsername(): String? {
        return email
    }
}
y
You can do
Copy code
@set:JvmName("_getPassword") var password: String
t
Thanks for answer! I tried using that annotation, but it gives me the same error
p
@get:
not
@set:
❤️ 3
t
omg... Thank you!
o
The answers are technically correct (the best kind of correct), but you shouldn't have these getters at all. You already have them just by declaring the properties as public. That's why you have the clash - because the compiler already generates getters for you.
And you have to change the validation annotations to
@field:
on your constructor properties, otherwise they will be ignored by the validation engine - assuming you use HIbernate Validator.
Actually, I see the getters come from the interface. My bad, sorry about that.
t
I was just about to answer about that, all 3 methods come from the UserDetails interface. Thanks for pointing out about the @field:, I didn't know about that
o
FYI you can also provide stronger type guarantees in your override methods - you may declare the return type of
getEmail
and
getPassword
as
String
since your User properties are never null.
gratitude thank you 1