小编Mic*_*ann的帖子

为什么Java语言没有提供通过注释声明给定"字段"的getter和setter的方法?

我实际上很高兴地设计和开发Java EE应用程序已经有9年了,但我最近意识到,随着时间的推移,我越来越厌倦了将所有这些丑陋的bean类与他们的getter和setter一起拖延.

考虑像这样的基本bean:

public class MyBean {

    // needs getter AND setter
    private int myField1;

    // needs only a getter, no setter
    private int myField2;

    // needs only a setter, no getter
    private int myField3;

    /**
     * Get the field1
     * @return the field1
     */
    public int getField1() {
            return myField1;
    }

    /**
     * Set the field1
     * @param value the value
     */
    public void setField1(int value) {
            myField1 = value;
    }

    /**
     * Get the field2
     * @return the …
Run Code Online (Sandbox Code Playgroud)

java syntax

4
推荐指数
1
解决办法
1191
查看次数

标签 统计

java ×1

syntax ×1