BooleanFlag (Java SE 26 & JDK 26)
Description: declaration: module: jdk.jfr, package: jdk.jfr, annotation type: BooleanFlag
Keywords: jdk.jfr.BooleanFlag class

# Annotation Interface BooleanFlag

@Retention(RUNTIME) @Target({FIELD,TYPE,METHOD}) public @interface BooleanFlag
Event field annotation, specifies that the value is a boolean flag, a `true` or `false` value.

The following example shows how the `BooleanFlag` annotation can be used to describe that a setting is a boolean value. This information can be used by a graphical user interface to display the setting as a checkbox.

    @BooleanFlag
    @Name("example.Rollback")
    @Label("Rollback")
    @Description("Include transactions that are rollbacked")
    public static class RollbackSetting extends SettingControl {
        private static final String DEFAULT_VALUE = "true";
        private boolean value = true;

        @Override
        public String combine(Set<String> values) {
            if (values.contains("true")) {
                return "true";
            }
            if (values.contains("false")) {
                return "false";
            }
            return DEFAULT_VALUE;
        }

        @Override
        public void setValue(String value) {
            // Ignore invalid values
            if ("true".equals(value) || "false".equals(value)) {
                this.value = "true".equals(value);
            }
        }

        @Override
        public String getValue() {
            return Boolean.toString(value);
        }

        public boolean shouldEmit() {
            return value;
        }
    }

    @Name("example.Transaction")
    public static class TransactionEvent extends Event {
        @Label("Context")
        String context;

        @Label("Rollback")
        boolean rollback;

        @SettingDefinition
        @Name("rollback")
        public boolean rollback(RollbackSetting rollbackSetting) {
            return rollback && rollbackSetting.shouldEmit();
        }
    }

Since:
  9