Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1507

Allow Builders to be completely generic

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.7
    • Configurators
    • None

    Description

      Allow Builders to be completely generic. This is not just supporting Builder<T>, which works in 2.6.2, but to allow declarations like Builder<B extends Builder<B>> combined with setters that return B.

          public static class Builder<B extends Builder<B>> implements org.apache.logging.log4j.core.util.Builder<ValidatingPluginWithGenericBuilder> {
      
              @PluginBuilderAttribute
              @Required(message = "The name given by the builder is null")
              private String name;
      
              public B withName(final String name) {
                  this.name = name;
                  return asBuilder();
              }
      
              @SuppressWarnings("unchecked")
              private B asBuilder() {
                  return (B) this;
              }
      
              @Override
              public ValidatingPluginWithGenericBuilder build() {
                  return new ValidatingPluginWithGenericBuilder(name);
              }
          }
      

      (I have a patch for this)

      (The next step (and ticket) will be to allow to use a Builder that extends another Builder.)

      Attachments

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              ggregory Gary D. Gregory
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: