android使用lombok_用Lombok访问器绑定Android吗?

在尝试使用Lombok访问器绑定Android时遇到了错误。尽管标准的1-way绑定已足够,但Lombok的访问器会导致编译错误。通过在'lombok.config'中设置'getter.noIsPrefix=true',可以避免为boolean类型的属性手动编写getters和setters。
摘要由CSDN通过智能技术生成

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;

}

*/

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值