把set方法都改成这样的话,可以实现流式编程风格,这样做有什么弊端?返回this的时候会多一次引用拷贝吗?
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
There are no disadvantages to doing this. When returning this, the overhead of an extra copy of the reference can be ignored.
However, I suggest keeping the setter as it is. If you want fluent style, then get another Builder. In your example it would look like this:
ActphyCardRequestBuilder builder = new ActphyCardRequestBuilder(); ActphyCardRequest request = builder.cardType(...).cardCode(...).build();
You are overthinking, returning this is just to facilitate your chain calls
There are no disadvantages to doing this. When returning this, the overhead of an extra copy of the reference can be ignored.
However, I suggest keeping the setter as it is. If you want fluent style, then get another Builder. In your example it would look like this:
You are overthinking, returning this is just to facilitate your chain calls