user
07/01/2017, 11:44 AMhttps://kotlinlang.slack.com/files/U61V368AC/F622WUBNV/img_20170701_160509.jpg▾
karelpeeters
07/01/2017, 12:36 PMProperty delegates don’t have to implement any interface, but they have to provide a getValue() function (and setValue() — for var's).Why didn't they make it a requirement to implement the interface? Why do they have this one case of duck-typing, while the rest of the language requires implementing interfaces?
karelpeeters
07/01/2017, 12:37 PMkirillrakhman
07/01/2017, 12:39 PMiterator()
method that returns an iterator can be used in a for
loop. This is the reason you can use Sequences
in a for
loopkirillrakhman
07/01/2017, 12:41 PMfor (i in iterator)
because there is an extension function fun Iterator.iterator() = this
kirillrakhman
07/01/2017, 12:41 PMgetValue
and it will work for delegates, tooilya.gorbunov
07/01/2017, 12:42 PMkarelpeeters
07/01/2017, 1:05 PMkarelpeeters
07/01/2017, 1:11 PMkirillrakhman
07/01/2017, 1:36 PMraulraja
07/01/2017, 1:47 PMkarelpeeters
07/01/2017, 2:22 PMkarelpeeters
07/01/2017, 2:26 PMkarelpeeters
07/01/2017, 3:18 PMalwyn
07/01/2017, 6:35 PMdumptruckman
07/02/2017, 4:19 AMprivate val messages = HashMap<LocalizablePlugin, Map<Array<Any>, Message>>()
internal fun getMessageKeys(localizablePlugin: LocalizablePlugin): Set<Array<Any>> {
if (!messages.containsKey(localizablePlugin)) {
throw IllegalArgumentException("Provider has no registered messages.")
}
return messages[localizablePlugin].keys
}
dumptruckman
07/02/2017, 4:19 AMkarelpeeters
07/02/2017, 6:48 AMvaskir
07/02/2017, 6:49 AMsitepodmatt
07/02/2017, 1:39 PMsitepodmatt
07/02/2017, 1:41 PMkarelpeeters
07/02/2017, 2:27 PMsitepodmatt
07/02/2017, 4:11 PMsitepodmatt
07/02/2017, 4:13 PMkarelpeeters
07/02/2017, 4:19 PMResource
, and you want to get the list of conditions from it. In the first case you'd get a List<ResourceCondition>
. Maybe that's enough for you, but maybe you actually want/need to know what kind of conditions they are. The second case allows for this, you can have an instance of AltResource<MyCondition>
, and you could get a list from it with type List<MyCondition>
, allowing you to invoke MyCondition
-specific behaviour.karelpeeters
07/02/2017, 4:20 PMpniederw
07/02/2017, 6:14 PMpniederw
07/02/2017, 6:17 PMeygraber
07/02/2017, 7:09 PMString.isNullOrBlank
smart cast to not null? For instance, the following function won't compile:
class Test(val name: String?)
fun test(test: Test): String {
val name = test.name
if(name.isNullOrBlank()) {
"null or blank"
}
else {
name
}
}
karelpeeters
07/02/2017, 7:27 PMvar a: String? = "hey"
var b: String =
if (a.isNullOrEmpty() || a == null) {
"empty"
}
else {
a
}