we also discuss about nullable type wish example and non-nullable without example and see what is the common way to handle null pointer exception. Example fun main(args: Array) ) and implemented with a an example see the result after compile. If the variable is null it will simply return null otherwise perform action. Use it only if you don’t mind getting the null value in the output console. Process:, PID: 31405 kotlin.UninitializedPropertyAccessException: lateinit property adapterPosts has not been initialized at .HomeFragment. So how to assign the null value to our variable of name so for that in kotlin we have something called nullable datatype to do that we have to make this string as nullable by using the question mark here so this rectify is our error now similar to string you can create an allowable integer or a nullable float value similarly nullable boolean value and0 even the custom classes such as student or employee so right now I will use the nullable string value now let us try to explode our null safety operators so here these are the comment statements where we will explore all the full types of null safety operators There are four types of null safety operators. In kotlin by default the null value is not supported to avoids the null pointer exception we have a lot of null safety operators which helps to avoid the null pointer exception and makes our application more robust and errors.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |