miqbaldc
08/25/2019, 2:30 PMfun fun1(list: List<DataA>)
fun fun1(list: List<DataB>)
The current condition declaration was clashed. any workaround?
1. I've tried to use typealiases
but it still clashed. e.g: typealias ListDataA = List<DataA>
2. Using extensions function, still clashed. e.g: ListDataA.fun1()Florian
08/26/2019, 10:59 AMwhen
doesn't have a short form for !=
right?Aslam Hossin
08/28/2019, 2:46 AMInt
optional parameter?am
08/28/2019, 9:30 AMinternal
key word
eg
internal const NAME_FOO:String = " "
class Foo{
}
Florian
08/28/2019, 9:53 AM<
etc are not supported in when
(I mean in the same way as in
and is
)Florian
08/29/2019, 1:29 PMwhen
statement?matt tighe
08/29/2019, 6:07 PMinterface ErrorField
data class InputError(
val field: ErrorField
val message: String
)
// elsewhere
internal sealed class Field : ErrorField {
object MyField : Field()
}
// complains about exhaustiveness
return when (error.field) {
is Field.MyField -> {}
}
is there a way to get the behavior i’m looking for? that is, to have a generally defined type but have the exhaustiveness check be aware that the subtype is actually exhausted?Florian
08/30/2019, 8:36 AMwhen
without an argument and I want to put 2 cases into 1 branch I have to divide them with || , right?matt tighe
08/30/2019, 8:58 PMinterface Entity
internal class MyClassEntity : Entity {}
interface Model
class MyClass {} : Model
interface Repository<M: Model, E: Entity> {
fun constructEntity(model: M): E
}
basically I want to expose MyClass
and implementations of Repository
, but I want some way to construct entities internally and still have them be part of a contractFlorian
08/31/2019, 8:30 PMwhen
without an argument is a replacement for an if-else-if
ladder. But why particularly the argument-less one? Isn't it also a replacement for if-else-if
when it has an argument?ursus
09/01/2019, 5:28 AMLastExceed
09/03/2019, 3:29 AMfun Foo(x: Float?): Boolean {
var result = false
if (x != null) {
result = x > 1f
}
return result
}
can this be simplified? maybe using elvis operator somehow?hooliooo
09/03/2019, 6:35 AMMarko Mitic
09/03/2019, 11:06 AMsuspend inline fun <reified T> get(key: String): T? =
dao.getById(key)?.let {
when (T::class) {
String::class -> it.value as T
Int::class -> it.value.toInt() as T
Float::class -> it.value.toFloat() as T
Double::class -> it.value.toDouble() as T
else -> throw IllegalArgumentException("Not implemented for the given type.")
}
}
sandi
09/04/2019, 4:22 PMdata class User(val name: String, val email: String)
val user: User get() = User(email = getEmail(), name = getName())
What is the order of execution here? Do named arguments get resolved (1) according to the data class argument positioning or (2) when creating the object with named arguments?mathew murphy
09/04/2019, 6:34 PMStringer
in Go?mathew murphy
09/04/2019, 6:35 PMJohan Alkstål
09/07/2019, 8:59 PMMorgan
09/07/2019, 9:07 PMJohan Alkstål
09/09/2019, 2:24 PMJohan Alkstål
09/09/2019, 2:45 PMDonal
09/10/2019, 8:42 AMRoqueRueda
09/10/2019, 2:13 PMfun addVisibilityListener(listener: (Int) -> Unit = {})
I want to create a list of listeners, It is possible to have a list of lambdas? or how can I handle that scenario?david-wg2
09/10/2019, 2:22 PM"<my-tag>...</my-tag>".removePrefix("<").takeWhile { it != '>' }
Akhil Suseelan
09/10/2019, 3:37 PMassociateTo
?jk2018
09/11/2019, 4:38 PMAndrew Walker
09/11/2019, 5:13 PMEmilio
09/11/2019, 7:26 PMwhen
. So I have something like (class internals omitted)
sealed class Node
sealed class SourceNode : Node() // No parents
sealed class SinkNode : Node() // No children
sealed class OpNode : Node()
// classes that extend the sealed classes here
I would like to distinguish at the type level nodes that have parents and nodes that have children so I could write something like:
fun foo(x: ParentNode): ParentNode {
// Do something to only parent nodes, possibly exhaustively match on them, and return a ParentNode
}
Where ParentNode
is somehow a subtype of Node
The problem is OpNode
is both a parent node and a child node which calls for multiple inheritance via interfaces, but I would like to be within the land of sealed classes for exhaustive matching. Is there a solution to this in kotlin?Johan Alkstål
09/11/2019, 7:43 PMFoo
, when making a List<Foo>
should be possible without casting the classes to their interface type?
When I do
fun listOfFoos(): List<Foo> {
return listOf(
FooA(),
FooB(),
FooC()
)
}
it complains that each class is not a Foo
but a FooA
FooB
and FooC
.
I would have thought that since they all implement the interface Foo
it would just work?Florian
09/12/2019, 7:27 AMUnit
the equivalent of Java's Void
rather than lowercase void
?Florian
09/12/2019, 7:27 AMUnit
the equivalent of Java's Void
rather than lowercase void
?spand
09/12/2019, 7:28 AMkarelpeeters
09/12/2019, 7:29 AMVoid
doesn't have an instance but it allows null
so that's kind of the single instance.Luca Nicoletti
09/12/2019, 7:31 AMRuckus
09/12/2019, 1:36 PMVoid
id equivalent to Kotlin's Nothing?
Luca Nicoletti
09/12/2019, 3:54 PMVoid?
Nothing
can’t return, only throws or keep workingRuckus
09/12/2019, 4:01 PMVoid
, that's from java. Nothing
can't return, but Nothing?
can return only null
, just like Java's Void
.Luca Nicoletti
09/12/2019, 4:02 PMUnit?
Ruckus
09/12/2019, 4:02 PMUnit?
can return Unit
or null
Luca Nicoletti
09/12/2019, 4:03 PMUnit
is mapped to Void
in JavaRuckus
09/12/2019, 4:05 PMUnit
is mapped to void
(lowercase) for return type in Java, but stays as Unit
in other circumstances, such as generics.Luca Nicoletti
09/12/2019, 4:06 PMUnit?
is mapped to?Ruckus
09/12/2019, 4:06 PMUnit?
Luca Nicoletti
09/12/2019, 4:07 PMRuckus
09/12/2019, 4:07 PMLuca Nicoletti
09/12/2019, 4:07 PMUnit?
in Java…..Ruckus
09/12/2019, 4:10 PMUnit
, but with Java;s implied nullability.Luca Nicoletti
09/12/2019, 4:10 PMRuckus
09/12/2019, 4:11 PM// Test.kt
fun test(): Unit? {
return null
}
// Test.java
TestKt.test(); // returns kotlin.Unit
Luca Nicoletti
09/12/2019, 4:12 PM