Extensions Flashcards
Extensions
Extension functions are dispatched ___, i.e. they are not virtual by receiver type. This means that the extension function being called is determined by the type of the expression on which the function is invoked, not by the type of the result of evaluating that expression at runtime.
statically;
This example prints “Shape”, because the extension function being called depends only on the declared type of the parameter s, which is the Shape class.
Extensions
If a class has a member function, and an extension function is defined which has the same receiver type, the same name, and is applicable to given arguments, the ___ always wins.
member;
This code prints “Class method”.
Extensions
Note that extensions can be defined with a ___ receiver type. Such extensions can be called on an object variable even if its value is null, and can check for ‘this == null’ inside the body.
nullable
Extensions
Similar to extension functions, Kotlin also supports ___ ___. Initializers are not allowed for these types of properties.
extension properties
Extensions
If a class has a ___ object defined, you can also define extension functions and properties for the ___object.
companion
Extensions
The instance of the class in which the extension is declared is called ___ ___, and the instance of the receiver type of the extension method is called ___ ___.
dispatch receiver; extension receiver
Extensions
In case of a name conflict between the members of the dispatch receiver and the extension receiver, the ___ receiver takes precedence.
extension
Extensions
To refer to the member of the dispatch receiver you can use the ___ ___ syntax.
qualified; this
Extensions
Extensions declared as members can be declared as ___ and ___ in subclasses. This means that the dispatch of such functions is ___ with regard to the dispatch receiver type, but ___ with regard to the extension receiver type.
open; overriden; virtual; static