Commit 2b427173 authored by Him188's avatar Him188

Expose val instead of var

parent c9ac5d61
...@@ -28,11 +28,13 @@ abstract class Event : Subscribable { ...@@ -28,11 +28,13 @@ abstract class Event : Subscribable {
/** /**
* 事件是否已取消. 事件需实现 [Cancellable] 才可以被取消, 否则这个字段为常量值 false * 事件是否已取消. 事件需实现 [Cancellable] 才可以被取消, 否则这个字段为常量值 false
*/ */
var cancelled: Boolean = false val cancelled: Boolean get() = _cancelled
private var _cancelled: Boolean = false
get() = field.takeIf { this is Cancellable } ?: false get() = field.takeIf { this is Cancellable } ?: false
private set(value) = if (this is Cancellable) { private set(value) =
check(!field); field = value if (this is Cancellable) field = value
} else throw UnsupportedOperationException() else throw UnsupportedOperationException()
/** /**
* 取消事件. 事件需实现 [Cancellable] 才可以被取消 * 取消事件. 事件需实现 [Cancellable] 才可以被取消
...@@ -40,7 +42,7 @@ abstract class Event : Subscribable { ...@@ -40,7 +42,7 @@ abstract class Event : Subscribable {
* @throws UnsupportedOperationException 如果事件没有实现 [Cancellable] * @throws UnsupportedOperationException 如果事件没有实现 [Cancellable]
*/ */
fun cancel() { fun cancel() {
cancelled = true _cancelled = true
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment