Ifvwm
07/18/2019, 5:04 AMKrzysztof Kocel
07/18/2019, 9:14 AMclass User {
var id: String? = null
var name: String? = null
}
and list of pairs:
val fieldsToChange = listOf<Pair<String, String>>(Pair("name", "foo"), Pair("id", "bar"))
I would like to iterate trough list of pairs and set appropriate values for given properties using reflection.
How I can achieve this using kotlin reflection?aaverin
07/18/2019, 10:54 AMthiagoretondar
07/18/2019, 12:35 PMJobs
stored in a List<Job>
are completed?Liam Humphreys
07/18/2019, 1:02 PMrrader
07/18/2019, 7:50 PMmathew murphy
07/18/2019, 9:06 PMIfvwm
07/19/2019, 2:32 AMAndrew Gazelka
07/19/2019, 5:40 AMAny
extend Unit
? This would be nice for overriding functions…Ifvwm
07/19/2019, 6:29 AMIfvwm
07/19/2019, 6:31 AMDavid Cuesta
07/19/2019, 6:40 AMSyed Faraz
07/19/2019, 9:10 AMmapto
plus takeif
in chain, so that only those which satisfy operation are mapped to an arraylist?LeoColman
07/19/2019, 2:03 PMSuraj Shah
07/19/2019, 3:23 PMreturn@tryLambdas
should throw an error here right?
It does if i make it return String
directly instead of generics.
not sure what is going on here, could this be cause of type erasure?
inline fun T tryLambdas(lamb : () -> T) : T{
return lamb.invoke()
}
fun main() {
tryLambdas<String>{
return@tryLambdas // this should throw an error, but it doesnt. on decompiling it replaces it with Unit.INSTANCE
}
}
sonofblip
07/19/2019, 7:14 PM!!
always makes me feel icky
val x: Int? = getAnIntegerOrMaybeANullFromAPlaceO
if (x != null) {
functionThatTakesNonNullableIntegerArgument(x) // won't compile because it thinks x is nullable
functionThatTakesNonNullableIntegerArgument(x!!) // will compile because added !!
} else {
// handle the null case
}
mathew murphy
07/19/2019, 7:45 PMRuckus
07/19/2019, 8:01 PMvoid
return as Nothing
instead of Unit
?Rafa
07/19/2019, 9:31 PMAny reference in Java may be null, which makes Kotlin's requirements of strict null-safety impractical for objects coming from Java. Types of Java declarations are treated specially in Kotlin and called platform types. Null-checks are relaxed for such types, so that safety guarantees for them are the same as in Java
It seems as though it was a conscious decision to make the platform conform to Java. There are tradeoffs with all those choices, but curious as to why the reasoning was made to create the platform type instead of treating everything as nullable?egorand
07/20/2019, 2:55 AMT
which gets flattened into a list of T
. Here’s an example:
[[1, 2, 3], [4], [5, 6]] -> flatten -> [1, 2, 3, 4, 5, 6]
Pere Casafont
07/20/2019, 12:25 PMRodrigo Silva
07/20/2019, 5:09 PMAndrew Gazelka
07/20/2019, 9:06 PMHullaballoonatic
07/21/2019, 12:02 AMUzi Landsmann
07/21/2019, 4:58 AMTim Kuzmin
07/21/2019, 1:49 PMfun <T> Boolean.ternary(first: T, second: T) =
if (this) first
else second
Any pro-programmer will tell u that in cases like this
(stringA != null).ternary(stringA!!, stringB!!)
we will have npe(parameters of function calculates before call).
Lets make our function inline and add reified type:
inline fun <reified T> Boolean.ternary(first: T, second: T) =
if (this) first
else second
Nice! Now for non-primitives classes we will not have any trouble.
I guess u’ve already understand what I mean. For primitives it doesnt work, cause even for inline function kotlin calculates primitive expressions and then call function. For me it’s looks like a bug. Does anybody know will it be fixed for next versions?Ifvwm
07/21/2019, 3:08 PMfun counter():()->Int{
var c=0
fun g():Int{
c++
return c
}
return g
}
why “Function invocation g() expected”?robstoll
07/21/2019, 4:19 PMHullaballoonatic
07/21/2019, 4:49 PMHullaballoonatic
07/21/2019, 4:53 PMHullaballoonatic
07/21/2019, 4:53 PMmbonnin
07/21/2019, 4:54 PMShawn
07/21/2019, 5:00 PM>>Kotlin provides Data Classes to define classes that store only properties. In Java programming, classes that store only properties are not unusual, but regular classes are used for this purpose. Kotlin has given provision to exclusively define classes that store properties alone. These data classes do not have any methods but only properties. A data class does not contain a body, unlike a regular class. data keyword is used before class keyword to define a data class.
mbonnin
07/21/2019, 5:07 PMlouiscad
07/22/2019, 9:57 PMmbonnin
07/22/2019, 9:58 PMlouiscad
07/24/2019, 1:54 PMShawn
07/24/2019, 2:35 PMmbonnin
07/24/2019, 6:47 PMShawn
07/24/2019, 6:49 PMmbonnin
07/24/2019, 7:35 PM