Gary Gregory created LOG4J2-1507:
------------------------------------

             Summary: Allow Builders to be completely generic
                 Key: LOG4J2-1507
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1507
             Project: Log4j 2
          Issue Type: New Feature
          Components: Configurators
            Reporter: Gary Gregory
            Assignee: Gary Gregory
             Fix For: 2.7


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}}.

{code:java}
    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);
        }
    }
{code}

(I have a patch for this)

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



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to