![]() ![]() The opposite is true of - it tells the Kotlin compiler to treat the method result as a non-null type, forbidding you from assigning that result to null later in your program. If you try, Android Studio will notify you of an error, and the Kotlin compiler will throw an error in your build. The annotation ensures that when using the result of getCurrentName in a Kotlin file, you can’t dereference it without a null check. Fortunately, the Kotlin compiler recognizes annotations on Java programming languages methods that indicate whether they produce nullable or non-nullable values. Not all of your (or Android’s) APIs are written in Kotlin. ![]() How does nullability work with the Java programming language? We hear over and over again that this feature of Kotlin gives developers more peace of mind and leads to higher quality apps for end users. This aspect of Kotlin makes your code safer - if you later call a method or try to access a property on a non-null variable like x, you know you’re not risking a null pointer exception. When writing code in Kotlin, you can use the question mark operator to indicate nullability: ![]() In this post, we’ll look at how the Android 11 SDK does more to expose nullability information in its APIs and show how you can prepare your Kotlin code for it. One feature we love about Kotlin is that nullability is baked into its type system - when declaring a reference, you say upfront whether it can hold null values. Last May at Google I/O, we announced that Android was going Kotlin first, and now over 60% of the top 1000 Android apps use Kotlin. Posted by David Winer, Kotlin Product Manager ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |