Rejected method not obsolete

Some Java classes must have private properties with a public recipient and installer to work properly. For example, they need JSF beans and JPA objects. If it weren’t for these libraries, perhaps there are some properties that should not have any getters and should definitely not be installed. Also, empty constructors are often discouraged for using custom code. for instance

@Entity
public class MyEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public MyEntity() {}

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}

In this class, the setId method should never be called using manual code. This method is not deprecated, so the @Deprecated annotation will be incorrect.

Is there any other way than @Deprecated to indicate that the method should not be used?

+5
source share
2 answers

JPA . ( , EclipseLink Hibernate, , , ).

, . . Java, getters/seters. / ( imo) .

, , , . , , , .

/**
 * WARNING! DO NOT USE THIS UNLESS YOU ARE GOD!
 * This will probably break stuff unless...
 * ....
 */
public void doEvilHackishThings()
{
    // Stuff happens here.
}

, , . , .. , . , , .

+3

, , . Tell, , , . .

0

All Articles