Stay organized with collections
Save and categorize content based on your preferences.
WatchEvent
interface WatchEvent<T : Any!>
An event or a repeated event for an object that is registered with a WatchService
.
An event is classified by its kind
and has a count
to indicate the number of times that the event has been observed. This allows for efficient representation of repeated events. The context
method returns any context associated with the event. In the case of a repeated event then the context is the same for all events.
Watch events are immutable and safe for use by multiple concurrent threads.
Summary
Nested classes |
abstract |
An event kind, for the purposes of identification.
|
abstract |
An event modifier that qualifies how a Watchable is registered with a WatchService .
|
Public methods |
abstract T |
Returns the context for the event.
|
abstract Int |
Returns the event count.
|
abstract WatchEvent.Kind<T>! |
Returns the event kind.
|
Public methods
context
abstract fun context(): T
Returns the context for the event.
In the case of ENTRY_CREATE
, ENTRY_DELETE
, and ENTRY_MODIFY
events the context is a Path
that is the relative
path between the directory registered with the watch service, and the entry that is created, deleted, or modified.
Return |
T |
the event context; may be null |
count
abstract fun count(): Int
Returns the event count. If the event count is greater than 1
then this is a repeated event.
Return |
Int |
the event count |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# WatchEvent\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nWatchEvent\n==========\n\n```\ninterface WatchEvent\u003cT : Any!\u003e\n```\n\n|-------------------------------|\n| [java.nio.file.WatchEvent](#) |\n\nAn event or a repeated event for an object that is registered with a [WatchService](/reference/kotlin/java/nio/file/WatchService).\n\nAn event is classified by its [kind](#kind()) and has a [count](#count()) to indicate the number of times that the event has been observed. This allows for efficient representation of repeated events. The [context](#context()) method returns any context associated with the event. In the case of a repeated event then the context is the same for all events.\n\nWatch events are immutable and safe for use by multiple concurrent threads.\n\nSummary\n-------\n\n| Nested classes ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract | [Kind](/reference/kotlin/java/nio/file/WatchEvent.Kind) An event kind, for the purposes of identification. |\n| abstract | [Modifier](/reference/kotlin/java/nio/file/WatchEvent.Modifier) An event modifier that qualifies how a [Watchable](/reference/kotlin/java/nio/file/Watchable) is registered with a [WatchService](/reference/kotlin/java/nio/file/WatchService). |\n\n| Public methods ||\n|-------------------------------------------------------------------------------------|--------------------------------------------------------------|\n| abstract T | [context](#context())`()` Returns the context for the event. |\n| abstract [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [count](#count())`()` Returns the event count. |\n| abstract [WatchEvent.Kind](/reference/kotlin/java/nio/file/WatchEvent.Kind)\\\u003cT\\\u003e! | [kind](#kind())`()` Returns the event kind. |\n\nPublic methods\n--------------\n\n### context\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun context(): T\n```\n\nReturns the context for the event.\n\nIn the case of [ENTRY_CREATE](/reference/kotlin/java/nio/file/StandardWatchEventKinds#ENTRY_CREATE:java.nio.file.WatchEvent.Kind), [ENTRY_DELETE](/reference/kotlin/java/nio/file/StandardWatchEventKinds#ENTRY_DELETE:java.nio.file.WatchEvent.Kind), and [ENTRY_MODIFY](/reference/kotlin/java/nio/file/StandardWatchEventKinds#ENTRY_MODIFY:java.nio.file.WatchEvent.Kind) events the context is a `Path` that is the [relative](/reference/kotlin/java/nio/file/Path#relativize(java.nio.file.Path)) path between the directory registered with the watch service, and the entry that is created, deleted, or modified.\n\n| Return ||\n|---|----------------------------------|\n| T | the event context; may be `null` |\n\n### count\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun count(): Int\n```\n\nReturns the event count. If the event count is greater than `1` then this is a repeated event.\n\n| Return ||\n|----------------------------------------------------------------------------|-----------------|\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the event count |\n\n### kind\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun kind(): WatchEvent.Kind\u003cT\u003e!\n```\n\nReturns the event kind.\n\n| Return ||\n|------------------------------------------------------------------------|----------------|\n| [WatchEvent.Kind](/reference/kotlin/java/nio/file/WatchEvent.Kind)\u003cT\u003e! | the event kind |"]]