kenkyee
09/08/2018, 2:24 AMkarelpeeters
09/08/2018, 9:01 AMDaniel Tam
09/08/2018, 12:35 PMJakub
09/08/2018, 2:35 PMmap
operator?Jakub
09/08/2018, 3:12 PMList<UserApi>
to List<User>
Marcin Wisniowski
09/08/2018, 6:10 PMoverride fun onBackPressed() {
drawer?.run {
if (!isDrawerOpen) {
openDrawer()
this
} else null
} ?: super.onBackPressed()
}
Paul Woitaschek
09/09/2018, 9:49 AMjw
09/09/2018, 11:48 PMAyden
09/10/2018, 2:42 AMJanar
09/10/2018, 11:17 AMimport java.security.MessageDigest
fun foo(rp: String) {
return bar(rp)
}
private fun bar(rp: String): ByteArray {
return MessageDigest.getInstance("SHA-256").digest(rp.toByteArray())
}
The generarted code for kotlin uses: Intrinsics.checkParameterIsNotNull
for foo
and generates if (rpId ==null)
in bar
. In the later case it throws a TypeCastException
in case of null and in former an IllegalArgumentException
.
So why does generated code need to handle null checks differently??bdawg.io
09/10/2018, 4:25 PMCommand+LMB
on it, but I’ll give Ctrl+B
a try next timechristophsturm
09/10/2018, 5:17 PMkarelpeeters
09/10/2018, 5:20 PMValV
09/10/2018, 9:02 PMcheck
in #getting-started channel of any interest for you?kristofdho
09/10/2018, 11:10 PMfun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> = take(count(pred) + 1)
DALDEI
09/10/2018, 11:21 PMDias
09/10/2018, 11:44 PMvar a: String? = null
var b: String = a as String
it doesn’t warn that this kind of cast might not be safeDias
09/10/2018, 11:56 PMfun main(args: Array<String>) = runBlocking<Unit> {
val startTime = System.currentTimeMillis()
val job = launch {
var nextPrintTime = startTime
var i = 0
while (i < 5) { // computation loop, just wastes CPU
// print a message twice a second
if (System.currentTimeMillis() >= nextPrintTime) {
println("I'm sleeping ${i++} ...")
nextPrintTime += 500L
}
}
}
delay(1300L) // delay a bit
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
}
but the code below that
fun main(args: Array<String>) = runBlocking<Unit> {
val job = launch {
try {
repeat(1000) { i ->
println("I'm sleeping $i ...")
delay(500L)
}
} finally {
println("I'm running finally")
}
}
delay(1300L) // delay a bit
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
}
is not being awaited to finish it’s job before cancellationwei
09/11/2018, 1:49 AMval a = com.mycompany.path1.MyEnum.GOOD
val b = com.mycompany.path2.MyEnum.GOOD
if (a == b) {
println("a == b")
}
This code actually compiles and runs. However, when I created 2 different enum classes by hand and put them into 2 paths, the code won’t compile and it will say something like:
Operator '==' cannot be applied to 'com.mycompany.path1.myEnum' and 'com.mycompany.path2.MyEnum'
Why?Doru N.
09/11/2018, 8:43 AMdata class DataSourceResponse(val response: Response)
data class Response(val notifications: List<Notification>)
data class Notification(id: Int)
I have a function which takes a DataSourceResponse as a param and a callback, which should return a modified DataSourceResponse, filtering out some of the notifications from it.
How should I implement this filtering and copy, considering the given model classes above. (immutable notifications list).
The closest I got, was doing something like this:
callback.onDataLoaded(
paramDataSourceResponse.copy (
response = paramDataSourceResponse.response.copy (
notifications = paramDataSourceResponse.response.notifications.filter { check(it) }
)
)
)
but it looks kinda ugly to me. Also, not having every class made data class, would make it even uglier. Are there any other solutions for this?david-wg2
09/11/2018, 8:52 AMprivate fun whenTest(a: Boolean, b: Boolean) = when {
a && b -> ""
!a && b -> ""
a && !b -> ""
!a && !b -> ""
}
colljos
09/11/2018, 9:24 AMinternal
keyword within the same module but from a different source set than main
,test
? (eg. I’m trying to use internal from an integrationTest
source set in the same module)ghedeon
09/11/2018, 10:35 AMAregev2
09/11/2018, 10:58 AMfun main(args: Array<String>) {
val wi = WrapInt(1)
val ws = WrapString("1")
println(wi)
println(ws)
}
inline class WrapInt(private val x: Int)
inline class WrapString(private val x: String)
In 1.3-M2 the the toString method was changed to a structure of a data class
but when calling it on a class that wraps a string it just prints out the contained string... (In JVM)
WrapInt(x=1)
1
In Kotlin Native though it works as expected...
giving this output:
WrapInt(x=1)
WrapString(x=1)
Ahmed Mamdouh
09/11/2018, 1:20 PMrobstoll
09/11/2018, 2:23 PMexists
.Paul Woitaschek
09/11/2018, 5:30 PMSlackbot
09/11/2018, 7:03 PMDaniele Segato
09/11/2018, 7:13 PMcompanion object
into some kind of reusable code?
The main problem is I need the Enum.values()
statically and the class name for strings. I also need to access the jsonValue
in the enum, but I can put it in an interface of the enum I guess, so that's not a big deal...
Any suggestion?
See the code below (please answer in thread)tschuchort
09/11/2018, 7:14 PMtschuchort
09/11/2018, 7:14 PMAndreas Sinz
09/11/2018, 7:15 PMShawn
09/11/2018, 7:16 PMinline fun <reified T> emptyGenericArray(): Array<T> {
return arrayOf()
}
bloder
09/11/2018, 7:17 PMinline fun <reified T> genericArrayOf() : Array<T> = arrayOf()
tschuchort
09/11/2018, 7:20 PMfun <A : Something> foo(bar: Class<A>): Array<A>
Allan Wang
09/11/2018, 7:48 PMkristofdho
09/11/2018, 7:50 PMarrayOfNulls<T>(0)
call, T
is again not reifiedtschuchort
09/11/2018, 7:53 PMkristofdho
09/11/2018, 7:54 PMtschuchort
09/11/2018, 7:57 PMfun <T> Array<T>.plus(element: T): Array<T>
though and if I return an arrayOfNulls<Any?>(0) as Array<T>
than calling that method on it will failkristofdho
09/11/2018, 8:00 PMplus
function already contains the type in this
(being an Array<T>
), if you're confused as to why it's not reifiedtschuchort
09/11/2018, 8:09 PMArray<T>
for any TarrayOfNulls<Any?>(0) as Array<SomeClass?>
already doesn't work 😕kristofdho
09/11/2018, 8:22 PMbloder
09/11/2018, 8:30 PMfun <T : Any> genericListOf() : List<T> = arrayOf<KClass<T>>().mapNotNull { it.objectInstance }
Do you know any solution like that to arrays?kristofdho
09/11/2018, 8:58 PMoverride fun <T : Something> foo(bar: Class<T>): Array<T>
= java.lang.reflect.Array.newInstance(bar, 0) as Array<T>
diesieben07
09/11/2018, 9:06 PMjava.lang.reflect.Array.newInstance
is the way to go if you need this. It's ugly but perfectly fine to use.tschuchort
09/12/2018, 9:07 PMdiesieben07
09/13/2018, 7:16 AM