英文:
Wrapper Boolean VS Primitive boolean
问题
我正在使用 Lombok。
这是我的 Metadata 文件的样子。
package com.some.test.check.meta;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class CSVSourceProbeMetaData {
private boolean backupEnabled;
private String streamingDir;
private String filePattern;
}
但是当我尝试在类文件中从这里访问 backupEnabled
时,它不会给我建议,而且显示为红色。
public Object execute() {
boolean backupEnabled = csvSourceProbeMetaData.isBackupEnabled();
String streamingDir = csvSourceProbeMetaData.getStreamingDir();
但是当我使用包装类时,它正常工作。这是因为我不能在这里使用原始的 boolean 类型,还是有其他原因?
英文:
I am using Lombok.
This is how my Metadata file looks like.
package com.some.test.check.meta;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class CSVSourceProbeMetaData {
private boolean backupEnabled;
private String streamingDir;
private String filePattern;
}
But when I try to access backupEnabled
from here in the class file, it doesn't give me suggestions and it is red.
public Object execute() {
boolean backupEnabled = csvSourceProbeMetaData.get_______();
String streamingDir = csvSourceProbeMetaData.getStreamingDir();
But when I use Wrapper class it works fine. Is this because I cannot use primitive boolean here or any other reason?
答案1
得分: 2
获取布尔值的getter方法名称将以"is"开头而不是"get",因此尝试使用"isBackupEnabled",这将与您一起工作。
查看此链接以获取更多详细信息:
https://www.baeldung.com/lombok-getter-boolean
英文:
The getter method name for boolean will start with is not get so try isBackupEnabled this will work with you
Check this for more details
https://www.baeldung.com/lombok-getter-boolean
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论