Skip to content

Instantly share code, notes, and snippets.

@npryce
Last active March 24, 2017 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npryce/09f3b82112b6836085bd70fb0d66fb73 to your computer and use it in GitHub Desktop.
Save npryce/09f3b82112b6836085bd70fb0d66fb73 to your computer and use it in GitHub Desktop.
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