包装布尔值 VS 原始布尔值

huangapple go评论96阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年3月15日 13:29:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/60689996.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定