0

Okay, so I have a parent class with Builder Pattern and private constructor:

    public class ExternalResult implements ExternalEntity {

    private String mConnectionStatus;

    private ResultSet mResultSet;

    /**
     * Creates a new instance for result .
     * 
     * @return new instance of {@link ExternalResult}
     */
    public static ExternalResult.Builder builder() {
        return new ExternalResult.Builder();
    }

    /**
     * Constructor.
     * 
     * @param builder
     */
    private ExternalResult(ExternalResult.Builder builder) {
        this.mConnectionStatus = builder.mConnectionStatus;
        this.mResultSet = builder.mResultSet;
    }

    /**
     * Builder class 
     */
    public static final class Builder {
        /** Connection status. */
        private String mConnectionStatus;

        /** Result set. */    
        private ResultSet mResultSet;

        /**
         * Prevents creation of Builder.
         */
        private Builder() {
        }

        /**
         * Sets connection status.
         * 
         * @param connectionStatus connection status.
         * @return
         */
        public ExternalResult.Builder setConnectionStatus(String connectionStatus) {
            this.mConnectionStatus = connectionStatus;
            return this;
        }

       /**
         * Sets the result set.
         * 
         * @param resultSet.
         * @return
         */
        public ExternalResult.Builder setResultSet(ResultSet resultSet) {
            this.mResultSet = resultSet;
            return this;
        }

        
        /**
         * Create a new result object.
         * 
         * @return
         */
        public ExternalResult build() {
            return new ExternalResult(this);
        }
    }
}

And I want to make a wrapper of it, but when I try to extend it in the subclass, it throws

Implicit super constructor ExternalListRemoteFolderResult() is undefined. Must explicitly invoke another constructor

But my constructor here is private and I can't invoke it. So should I try to extend it and how?

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
  • share code for ExternalListRemoteFolderResult class – sanjeevRm Sep 16 '21 at 05:13
  • It was meant to be ExternalResult. I wanted it to be simple code. I fixed it now – CodeSeeker Sep 16 '21 at 06:24
  • if you want to extend a class you need to provide at least one public or protected constructor. Some code analysis tool (like SonarQube) want you to declare the class as final if it only provides private constructors. Is ExternalResult exposing more public methods than ExternalEntity? – ddfra Sep 17 '21 at 17:47

0 Answers0