elect
09/30/2016, 10:51 AMclass LazyProperty(val initializer: () -> Int) {
private val lazyValue: Int? = null
get() {
if (field == null) field = initializer()
return field
}
val lazy: Int
get() = lazyValue!!
}
elect
09/30/2016, 10:51 AMinitializer
and the Int?elect
09/30/2016, 10:51 AMelect
09/30/2016, 10:52 AMvar initialized = false
val lazyProperty = LazyProperty({ initialized = true; 42 })
assertFalse("Property shouldn't be initialized before access", initialized)
val result: Int = lazyProperty.lazy
assertTrue("Property should be initialized after access", initialized)
assertEquals(42, result)
elect
09/30/2016, 10:53 AMelect
09/30/2016, 10:54 AMinitialized = true; 42
?yole
09/30/2016, 10:56 AMinitializer
parameter is a function that takes no parameters and returns an Int
yole
09/30/2016, 10:56 AM{ initialized = true; 42 }
is passed as the argument for that parameterelect
09/30/2016, 11:08 AMyole
09/30/2016, 11:10 AMvoddan
09/30/2016, 11:51 AMassertDoubleWithPressision
in stdlib. Is there any?voddan
09/30/2016, 12:15 PMelect
09/30/2016, 1:07 PM===
here?
fun compareStrings(s1: String?, s2: String?) {
s1 == s2
// is compiled to
s1?.equals(s2) ?: s2 === null
}
spand
09/30/2016, 1:08 PMelect
09/30/2016, 2:29 PM<T, C: MutableCollection<T>> Collection<T>.partitionTo
instead a simple
MutableCollection<T>.partitionTo
yole
09/30/2016, 2:30 PMelect
09/30/2016, 2:42 PMfun <T> T.whatever
, does the part <T>
have a specific technical name?yole
09/30/2016, 2:42 PMelect
09/30/2016, 2:44 PMT
, I really mean the whole leading part <T>
pawegio
09/30/2016, 2:51 PMkevinmost
09/30/2016, 2:53 PM<>
in Java 7+pawegio
09/30/2016, 3:00 PMelect
09/30/2016, 3:01 PM(condition ? first : second).add(e)
elect
09/30/2016, 3:02 PMfirst
and second
are collections in this case for examplepaulblessing
09/30/2016, 3:07 PMif/else
can be used as an expression: (if (condition) first else second).add(e)
ilya.gorbunov
09/30/2016, 3:09 PMkqr
09/30/2016, 10:45 PMkqr
09/30/2016, 10:46 PMkqr
09/30/2016, 10:46 PMandrewoma
09/30/2016, 10:54 PMclass Foo(dateString: String) {
val date = LocalDate.parse(dateString)
}