Can you force a compiler warning or error in Kotlin/Java?

Viewed 562

Having a background in iOS development, I'm quite used to using this directive for intentionally triggering a compiler warning (in Swift):

#warning("This will output as a warning during compilation")

or this one to trigger an error:

#error("This will output as an error during compilation")

This is very useful if, for example, I need to defer attention to the code fragment in question, or when using conditional compiler directives. I really miss this feature during Android development (in Kotlin, preferably, but I'm also curious about a similar Java feature).

I'd like to know if there's at least an alternative for doing this, especially if it's integrated well into Android Studio and the compiler.

1 Answers

If you are talking about throwing an exception: throw new Exception("Exception message"); this is for Java. For Kotlin it's similar with a little change :Kotlin nothing exception

Related