KT.FORBIDDEN_VOID

Usages of 'Void' are forbidden

This rule detects usages of Void and reports them as forbidden. The Kotlin type Unit should be used instead. This type corresponds to the Void class in Java and has only one value - the Unit object.

Noncompliant Code

Copy
runnable: () -> Void
var aVoid: Void? = null

Compliant Code

Copy
runnable: () -> Unit
Void::class

Options

  • ignoreOverridden (default: False)

    ignores void types in signatures of overridden functions

  • ignoreUsageInGenerics (default: False)

    ignore void types as generic arguments

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html