关于javaBean的Set方法改为流式的缺陷?
高洛峰
高洛峰 2017-04-18 09:43:44
0
2
445

把set方法都改成这样的话,可以实现流式编程风格,这样做有什么弊端?返回this的时候会多一次引用拷贝吗?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template