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

Allow Builders to be completely generic

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7
    • Component/s: Configurators
    • Labels:
      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

              • Assignee:
                garydgregory Gary Gregory
                Reporter:
                garydgregory Gary Gregory
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: