Any way to do Android binding with Lombok accessors?

青春壹個敷衍的年華 提交于 2019-12-23 20:31:17

问题


I'm starting to play with Android binding. The standard (1-way) binding is to the point of being good enough for the people I hang out with.

However, I find that I can't use Lombok accessors without a Could not find accessor error. Have you found a way around this, shy of manually writing getters and setters like some kind of Lombok-ignorant cavebeast?

@Bindable
@Getter @Setter
private String stringField;

//Must uncomment hand-coded accessors to compile!
//public String getStringField() { return stringField;}
//public void setStringField(String s) { stringField = s;}

For posterity, my original sample code was using a boolean, which clouds the issue a little:

    @Bindable 
    @Getter @Setter private boolean showpassword = false;

/*  This only compiles if the handcoded accessors are uncommented.

    public boolean getShowpassword() {
        return showpassword;
    }
    public void setShowpassword(boolean b) {
        showpassword = b;
    }
*/

回答1:


For boolean, by default the generated "getter" is isShowpassword, following the beanspec. The generated "setter" is setShowPassword. The error message suggests it is the "getter" that cannot be found.

You can use a configuration key to change this behavior. According to the documentation, if you include the following in lombok.config your program should work without the hand written getter and setter:

lombok.getter.noIsPrefix = true


来源:https://stackoverflow.com/questions/37357932/any-way-to-do-android-binding-with-lombok-accessors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!