August 2017
Intermediate to advanced
440 pages
10h
English
Extension functions are most often used when we feel that a class defined by other programmers is missing a method. For example, if we think that View should contain the show and the hide methods, usage for which would be easier than visibility field setting, then we can just implement it ourselves:
fun View.show() { visibility = View.VISIBLE }
fun View.hide() { visibility = View.GONE }
There is no need to remember the names of classes that hold util functions. In the IDE, we just put a dot after the object, and we can search through all the methods that are provided together with this object extension function from the project and libraries. Invocation looks good, while it looks like ...
Read now
Unlock full access