-
Book Overview & Buying
-
Table Of Contents
Android Programming for Beginners - Fourth Edition
By :
There is much to learn about functions. Even after this chapter, we will continually encounter new scenarios involving functions throughout the rest of the book, not to mention the entire next chapter devoted to composable functions. What follows are some more commonly used function basics.
Sometimes we will want to plan the structure of the functions in our app by adding all the headers and coming back to implement the bodies (the code that does the work) later. At the same time, we want our code to compile so we can test other areas of the app. The TODO keyword lets us add headers for unimplemented functions. Take a look at this code.
fun calculateDiscount(price: Double): Double {
TODO("Implement discount calculation logic")
}
The preceding function compiles successfully, but when it is called, it throws a NotImplementedError, which crashes the app unless you handle it, including the message Implement discount calculation logic. We...