Migrating sure() (Kotlin M3 and Higher)

The sure() function is obsolete as of Kotlin M3. To remind you what it is, here’s the definition:

It asserts that the receiver expression is not equal to null. For example:

This function has been replaced by the more concise ‘!!’ operator that does exactly the same thing:

If you have some old code that uses sure, you can

  • (Not recommended) Copy the definition given above to you project
  • Migrate your code using a quick-fix in IntelliJ Plugin for Kotlin M3

Suppose you have an unresolved ‘sure’ in your code. Invoke a quick-fix by pressing Alt+Enter on the error:

All unresolved calls to ‘sure()’ in you project will be migrated to ‘!!’ at once:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">