How do you make Kotlin variables nullable by default?
A) Use it same like Java
B) Use !! to make variables nullable
C) Use $ to make variables nullable
D) Use ? to make variables nullable
D) Use ? to make variables nullable
Kotlin variables are not nullable by default.
Use ? to make variables nullable.
Example :
var marbles: Int? = null
Which one of these extension functions on
class ForestTrees( val color: String, val size: Int, private val cost: Double, val leafy: Boolean)
will give a compiler error?
A) fun ForestTrees.isRed() = color == "red"
B) fun ForestTrees.isBig() = size > 45
C) fun ForestTrees.isExpensive() = cost > 10.00
D) fun ForestTrees.isNotLeafy() = leafy == false
C) fun ForestTrees.isExpensive() = cost > 10.00
Since the cost is marked private
You will get this error message
⇒ error: cannot access 'cost': it is private in 'ForestTrees'
Difference between List<*> and List<Any>
A) List<*> and List<Any> both will accept only one type
B) List<*> will accept only one type, List<Any>will accept any number of types
C) List<Any>will accept only one type, List<*>will accept any number of types
D) List<*> and List<Any> both will accept any number of types
B) List<*> will accept only one type, List<Any>will accept any number of types
List<*> can contain objects of any type, but only that type, so it can contain Strings (but only Strings)
while List<Any> can contain Strings and Integers and whatnot, all in the same list