Home > Net >  Lombok's setter can't be called
Lombok's setter can't be called

Time:12-29

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.

Could you help me understand why it doesn't and how to cope with this problem?

CodePudding user response:

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

  • Related