mardi 24 avril 2018

Builder pattern does't return "this"

I used RestTemplateBuilder in spring boot today, and found its methods do not return "this", instead, they return a new builder instance.

public RestTemplateBuilder basicAuthorization(String username, String password) {
    return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
            this.messageConverters, this.requestFactory, this.uriTemplateHandler,
            this.errorHandler, new BasicAuthorizationInterceptor(username, password),
            this.restTemplateCustomizers, this.requestFactoryCustomizers,
            this.interceptors);
}

This is the first time I saw builder pattern not returning "this" at the end. Is there any good reason to do so?

Aucun commentaire:

Enregistrer un commentaire