Tag: 流畅接口

流畅的kotlin数据类方法

我们熟悉java和其他编程语言调用方法的流畅接口。 例如: Picasso.with(this).load(url).into(imageView); 这可以通过setter方法返回所需类型的对象。 public Picasso with(Context context) { this.context = context; return this; } public X load(String url) { this.url = url; return this; } public Y load(ImageView imageView) { this.imageView = imageView; return this; } 我正在努力做同样的kotlin数据类, 但遗憾的是我找不到一种方法来重写setter方法,我可以返回该对象的新实例。 当我尝试强制覆盖setter方法时,出现编译器错误。 任何有关可以做什么的想法都可以调用流畅的接口,或者至少改变setter的工作方式 data class CorruptOfficeAccount(…..){ override fun addCollectedFee(Long money) :CorruptOfficeAccount { this.money = money/5 } } […]