Kotlin酒店的私人吸气剂和公共二传手 [英] Private getter and public setter for a Kotlin property

查看:143
本文介绍了Kotlin酒店的私人吸气剂和公共二传手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Kotlin建造一个拥有私人吸气剂(或者只是没有吸气剂)但拥有公共制定者的物业?

How to make a property in Kotlin that has a private getter (or just do not have it) but has a public setter?

var status
private get

不适用于错误: Getter可见性必须与属性可见性相同

在我的情况下,原因是Java互操作:我想要我的Java代码能够调用 setStatus 但不能 getStatus

In my case, the reason is for Java interop: I want my Java code to be able to call setStatus but not getStatus.

推荐答案

目前,在Kotlin,我们不可能拥有一个具有比该属性更明显的二传手的属性。问题跟踪器中存在语言设计问题,请随时观看/投票或分享您的用例: https://youtrack.jetbrains.com/issue/KT-3110

It's impossible at the moment in Kotlin to have a property with a setter that is more visible than the property. There's a language design issue in the issue tracker on this, feel free to watch/vote for it or share your use cases: https://youtrack.jetbrains.com/issue/KT-3110

这篇关于Kotlin酒店的私人吸气剂和公共二传手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆