iex
01/21/2020, 3:39 PMregisterTypeAdapter(Date::class.java, DateDeserializer())
So when the object has a non optional Date
, it's clear that I should throw an exception if it gets an empty string. But when Date
is optional, I'd like to map the empty string to null
, i.e. the date will just be assigned null
. Not sure how to do that. It relates with lang, in that the deserializer is defined like this:
`JsonDeserializer<Date>`but I need it to work with Date?
basically.
I can of course create a getter in my object that deserializes the date if present, but I'd like to do this directly with the parser, not "outside".Sam Schilling
01/21/2020, 4:58 PMopen class Animal { ... }
// Using upper bound generic
fun <T: Animal> print(animal: T) { ... }
// Using type directly
fun print(animal: Animal) { ... }
It seems in both cases any subclasses of Animal
will work with the function call. In which case the second option seems more readable and condensed if they function identically.Sandy
01/21/2020, 5:32 PMWesley Acheson
01/21/2020, 5:44 PMLeoColman
01/21/2020, 7:41 PMluke
01/22/2020, 4:07 AM1914 1 5.9 0.9 --- 48.3 ---
What I have so far: ([\d]+)\.*([\s]+)
I just want to extract all the non-whitespace values into an Array.AnnoymousGiraf
01/22/2020, 4:15 AMClass A cosntructor(...) : (String) -> B {
}
user
01/22/2020, 12:33 PMiex
01/22/2020, 3:02 PMfor (handler in handlers) {
if (handler.handle(uri)) break
}
René
01/22/2020, 7:04 PMverify(sut).someMethod("example")
, but that throws always 3 invocations (two other where on other methods). I have right now no idea how to fix that testDavid Glasser
01/22/2020, 7:35 PMinline fun <T : Any> foo(X<T>): List<T> {
return objectMapper.readValue(xxx)
}
inline fun <reified T> ObjectMapper.readValue(content: String): T = ... # from jackson kotlin
How does the compiler create the reification of the T in the nested function if it's not reified in the outer function?Ellen Spertus
01/22/2020, 7:59 PMvar method: String? = null
try {
method = jsonResponse.getString("method")
} catch (exception: JSONException) {
Log.i(TAG, "No method provide by server.")
}
Michael Friend
01/22/2020, 10:20 PMval casted = nullable as? String
and
val casted = nullable as String?
?
They both smart cast to String?
but do they both give null if nullable
is null and nullable
casted to a string (assuming the cast is possible)?
I know using as?
returns null if the cast fails and i assume option 2 would throw an exception, is that the only difference?trathschlag
01/23/2020, 8:42 AMribesg
01/23/2020, 10:29 AMvar result: Result<T>? = null
// ...
return result!!.getOrThrow() // Expression of type kotlin.Result cannot be used as a left operand of '!!'
What is that supposed to mean? Why do I have to write (result as Result<T>).getOrThrow()
for it to compile?Marcin Wiśniewski
01/23/2020, 10:30 AM[INFO] Possible cache corruption. Rebuilding. <http://com.intellij.util.io|com.intellij.util.io>.PersistentEnumeratorBase$CorruptedException: PersistentEnumerator storage corrupted /builds/swb/api/api/target/kotlin-ic/compile/caches-jvm/inputs/source-snapshot.tab
<http://com.intellij.util.io|com.intellij.util.io>.PersistentEnumeratorBase$CorruptedException: PersistentEnumerator storage corrupted /builds/swb/api/api/target/kotlin-ic/compile/caches-jvm/inputs/source-snapshot.tab
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentEnumeratorBase.<init>(PersistentEnumeratorBase.java:221)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentBTreeEnumerator.<init>(PersistentBTreeEnumerator.java:73)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentEnumeratorDelegate.<init>(PersistentEnumeratorDelegate.java:47)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentHashMap.<init>(PersistentHashMap.java:163)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentHashMap.<init>(PersistentHashMap.java:152)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentHashMap.<init>(PersistentHashMap.java:143)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentHashMap.<init>(PersistentHashMap.java:135)
at <http://com.intellij.util.io|com.intellij.util.io>.PersistentHashMap.<init>(PersistentHashMap.java:128)
Problem occurs only on Gitlab-CI pipeline. Compilation on local machine works well. Can anybody help me to fix it?ribesg
01/23/2020, 11:13 AMMichael de Kaste
01/23/2020, 1:56 PMIanmedeiros
01/23/2020, 5:46 PMtipsy
01/23/2020, 8:45 PMtypealias Address = String
typealias Age = Int
when i see these typealiases used in signatures, i always assumed they're classes
is there a guideline on this? i personally find it very confusing, but it might just be because it's unfamiliarvoben
01/24/2020, 8:44 AM// Java code
try {
return doDangerousThing();
} catch (ExceptionA | ExceptionB e) {
e.printStackTrace();
}
GarouDan
01/24/2020, 9:57 AMxcode-compat
, and the method that I’d like to expose is setupTask
(which is available here: https://github.com/Kotlin/xcode-compat/blob/6633fe0696c38c9eee2f789164b8b945910fdc13/xcode-compat/src/main/kotlin/org/jetbrains/kotlin/xcodecompat/XcodeCompatPlugin.kt#L27)
Please also note that this method will depend on other private ones.
I tested copying and pasting the plugin locally and then applying it, it works after that, but I don’t know if I can do that without forking the plugin. Can we?redenergy
01/24/2020, 11:44 AMjava.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.exposed.sql.Database
at gloomyfolken.bundle.common.mysql.MysqlContext.<init>(MysqlContext.kt:33)
at gloomyfolken.bundle.common.mysql.MysqlWorkerThread.openConnection(MysqlWorkerThread.kt:98)
at gloomyfolken.bundle.common.mysql.MysqlWorkerThread.run(MysqlWorkerThread.kt:109)
Caused by: java.lang.IllegalStateException: Can't load implementation for DatabaseConnectionAutoRegistration
at org.jetbrains.exposed.sql.Database.<clinit>(Database.kt:64)
... 3 more
ylemoigne
01/24/2020, 12:25 PMwhen
clause) Eg :
fun main() {
val myShortCutCondition = true
val s = when(2){
1 -> {
if(myShortCutCondition){
// return "shortcut" // for `s` value
}
// longCode
"1"
}
2 -> "2"
else -> ""
}
}
natpryce
01/24/2020, 2:56 PMGeorgi Naumov
01/25/2020, 3:22 PMNick Halase
01/25/2020, 8:32 PMpoohbar
01/26/2020, 2:27 AMString
to ensure that a string ends with a certain character? Also called "append if missing" in some libraries.
e.g.
foo("word", ".")
-> word.
foo("word.", ".")
-> word.
otakusenpai
01/26/2020, 8:32 AMotakusenpai
01/26/2020, 1:57 PMclass Usage(from: List<UsageArgument> = listOf(), val runsAt: List<RunAt> = listOf()) : List<UsageArgument> by from {
override fun toString(): String {
val result = joinToString(" ") { it.format() }
return if (result.isBlank()) "none" else result
}
}
can anyone explain this to me?
especially the parameters of the class def and the ending "by from". what does it mean?
the use case is like a list or something i suppose?otakusenpai
01/26/2020, 1:57 PMclass Usage(from: List<UsageArgument> = listOf(), val runsAt: List<RunAt> = listOf()) : List<UsageArgument> by from {
override fun toString(): String {
val result = joinToString(" ") { it.format() }
return if (result.isBlank()) "none" else result
}
}
can anyone explain this to me?
especially the parameters of the class def and the ending "by from". what does it mean?
the use case is like a list or something i suppose?Chills
01/26/2020, 2:00 PMFoso
01/26/2020, 2:01 PMChills
01/26/2020, 2:11 PMRay Eldath
01/26/2020, 6:49 PM