Search code examples
javalombokdowncast

Lombok's setter can't be called


package com.example.marketing.semantics.entities;

import com.example.marketing.general.entities.BaseEntity;
import com.example.marketing.general.interfaces.Phraseable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "extra_phrases",
        uniqueConstraints = {@UniqueConstraint(name = "unique_extra_phrase",
                columnNames = {"phrase"})})
public class ExtraPhraseEntity extends BaseEntity implements Phraseable {
    @NotNull
    @NotEmpty
    @Column(nullable = false,
            columnDefinition = "varchar(1000) default ''")
    private String phrase;

    @NotNull
    @Column(nullable = false,
            columnDefinition = "INTEGER DEFAULT 0")
    Integer frequency;
}

How I use it:

(ExtraPhraseEntity) phraseEntity.setPhrequency(frequency);

Result: my IDE signals: Cannot resolve method 'setPhrequency' in 'Phraseable'.

enter image description here

I cast type because if was Phraseable. So, I hoped that Lombok will help me with this setter method. But it doesn't.

Why does it not help me, and how can I cope with this problem?


Solution

  • Try ((ExtraPhraseEntity) phraseEntity).setPhrequency(frequency);