这是相关语法,从https://kotlinlang.org/docs/reference/grammar.html:
propertyDeclaration (used by declaration)
: modifiers? ('val' | 'var') typeParameters?
(receiverType '.')?
(multiVariableDeclaration | variableDeclaration)
typeConstraints?
(('=' expression) | propertyDelegate)? ';'?
((getter? (semi? setter)?) | (setter? (semi? getter)?))
;
propertyDelegate (used by propertyDeclaration)
: 'by' expression
;
我的看法是需要新的行,因为否则它假定private set
是propertyDelegate
中expression
的一部分.
事实上,在private set
是表达式的一部分的情况下,实际上可以编写一个函数单行程序.这是正确的功能代码:
val set = 0
var isRecording by mutableStateOf(false) private set
public infix fun <A, B> A.private(that: B): A = this
但我强烈建议不要写这样的代码哈哈.