Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unit? vs Unit vs ?. operator
override fun close() = client?.disconnect()

Return type of 'close' is not a subtype of the return type of the overridden member 'public abstract fun close(): Unit defined in java.lang.AutoCloseable'

Unit? is a supertype of Unit, not a subtype.

So, you have to do:

override fun close() { client?.disconnect() }

... which discards the result of client?.disconnect() and returns Unit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment