Section 1

Preview this deck

Will a getter and setter be generated for a val value? Why?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (7)

Section 1

(7 cards)

Will a getter and setter be generated for a val value? Why?

Front

No, only a getter since val is an immutable property

Back

Where does the rule "last line is the return value" doesn't apply?

Front

In regular functions with block bodies, they have to have an excplicit return statement.

Back

What is the precondition for a smart cast to work? Why?

Front

The property has to be a val and it cannot have a custom accessor so as to guaranteee that every access to the value would return the same value.

Back

if (e is Num) { val some = e as Num } What is redundant in the code above? Why?

Front

e as Num is redundant. Kotlin automatically casts e to Num whenever we check if (e is Num)

Back

What is the defaultg visibility modifier in Kotlin?

Front

public

Back

What is the syntax for a custom getter of a property?

Front

val someValue: Boolean get { //custom getter }

Back

var or val - what should you strive to use and why?

Front

val - it makes code closer to functional style and is using immutability

Back