Extensions Flashcards

1
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

member;

This code prints “Class method”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

A

nullable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Extensions

Similar to extension functions, Kotlin also supports ___ ___. Initializers are not allowed for these types of properties.

A

extension properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Extensions

If a class has a ___ object defined, you can also define extension functions and properties for the ___object.

A

companion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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 ___ ___.

A

dispatch receiver; extension receiver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Extensions

In case of a name conflict between the members of the dispatch receiver and the extension receiver, the ___ receiver takes precedence.

A

extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Extensions

To refer to the member of the dispatch receiver you can use the ___ ___ syntax.

A

qualified; this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

open; overriden; virtual; static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly