mercredi 15 septembre 2021

Class inheriting Builder Pattern class with private constructor

Okay, so I have a parent class with Builder Patern 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 ExternalListRemoteFolderResult build() {
        return new ExternalListRemoteFolderResult(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?

Aucun commentaire:

Enregistrer un commentaire