Sandy
09/26/2019, 5:08 PMDico
09/26/2019, 6:13 PMpublic String get(Integer key) {...}
public String get(int key) {...}
How can I call one of these without running into overload resolution ambiguity?Ifvwm
09/27/2019, 1:48 AMNikolay Kasyanov
09/27/2019, 8:00 AMinternal
class from a test within the same module (test & class packages are different though). According to the docs, it should work: https://kotlinlang.org/docs/reference/visibility-modifiers.html#modules (see "Modules", 3rd option). I'm using Kotlin Multiplatform though, hence my source sets are called commonMain
and commonTest
, not just main
and test
. Could this be causing this access issue? Is this a bug?Iaroslav Postovalov
09/27/2019, 10:44 AMJakub Komorowski
09/27/2019, 12:13 PMsetEnabled
method. I’ve overridden it in my class, and used properties from the child class in this overwrite. As the properties I’ve used were unmutable and non-nullable I was startled when my app crashed with NullPointerException
thrown in that method. Turns out it was called from the superclass constructor, and properties are initialized only after superclass constructor call. The simplified code that caused my problem looks something like: https://bit.ly/2n6xmm5 . When you run it, it throws NullPointerException
when using seemingluynon-nullable property.
Is there a pattern that would allow us to omit method calls on unitialized unmutable properties? I found two solutions to that problem, but I don’t think they’re very elegant. One using lateinit vars https://bit.ly/2nPYBBX - pretty ugly, and one using a flag https://bit.ly/2mgG4hq - pretty weird.
All of the urls are shortened https://play.kotlinlang.org code snippets.Mani
09/27/2019, 12:49 PMAndreas Unterweger
09/27/2019, 1:01 PMelseIf
it should allow me to take another value if the predicate does return true. i implemented the following extension function:
inline fun <T> T.elseIf(predicate: T.() -> Boolean, supplier: () -> T) : T =
when {
predicate() -> supplier.invoke()
else -> this
}
its called like val i = "ssss".elseIf({isEmpty()}) {"other"}
which feels very clumsy. can i optimize the syntax more? or arent there already alternatives in kotlin? or maybe im just missing the easy solution?karelpeeters
09/27/2019, 1:01 PMzkeme
09/27/2019, 5:13 PMgroostav
09/27/2019, 9:22 PMpackage asdf
fun Any.doThing() = TODO()
//...
package main
//no import statements
fun outer(){
42.doThing() //<-- auto import `asdf.dothing`?
//No! I want to write the fully-qualified invocation instead!
asdf.doThing(42) //error
42.asdf.doThing() //error
42.`asdf.doThing`() //error
}
xenoterracide
09/27/2019, 9:56 PMMani
09/28/2019, 10:53 AMChris Cunningham
09/29/2019, 4:05 AMinterface Event<out TS> { ... }
interface Event<out TS, out T0> { ... }
interface Event<out TS, out T0, out T1> { ... }
tschuchort
09/29/2019, 10:34 PM@NonNull
annotation on a parameter even though documentation (and common sense) says that it can be null. If I make the same parameter nullable in my overriding Kotlin method, the compiler complains to me that I'm not overriding. But if I don't, then the function will crash at the hidden parameter assertion that is generated automatically. How do I tell the compiler "shut up, I know what to do"? Can I disable null-assertions for just this method?Kamil K
09/30/2019, 10:34 AMfun x(anInt: Int) : String {
when (anInt) {
0 -> return "zero"
1 -> return "one"
}
return null!!
}
Despite the 'quality` of code itself I'm curious why compiler thinks that return null!!
is fine (IDE hints that return statement is unreachable which is false)?
And similarly why this val a : Int = null!!
is allowed as well.user
09/30/2019, 11:35 AMSteve Young
09/30/2019, 11:47 AMAndrew Gazelka
10/01/2019, 1:02 AMAkbar
10/01/2019, 8:05 AMjeggy
10/01/2019, 9:57 AMdalexander
10/01/2019, 2:24 PM// both Foo and Bar extend Item
val item: Any? = getSomething()
if(item is Foo || item is Bar) {
// I would expect this to smart cast to Item -- defining Item as a sealed class doesn't seem to help either
doThingWithItem(item) //Error - Type mismatch, required: Item, found Any?
}
Stephan Schroeder
10/02/2019, 10:32 AM"<test>.*</test>".toRegex()
.find("aaaa<test>5</test>aaaa<test>4</test>aaaa")
?.let { println("match: ${it.value}") }
doesn’t return the minimal first match <test>5</test>, but the longer one <test>5</test>aaaa<test>4</test> given that the documentation says: “Returns the first match of a regular expression” here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/find.html
And unfortunately findAll equally just returns a single match instead of two. Is there a way for me to fix this?
Playground link: https://pl.kotl.in/HA-C02_GySlackbot
10/02/2019, 2:45 PMSteve Young
10/02/2019, 3:42 PMGarouDan
10/02/2019, 5:37 PMabstract fun test() : String
can we, using somehow the new kotlin techniques to change the returning value of the function in the other abstract class which extend the first one, something like this?
fun test(): String {
return test().toString()
}
fun test(): Int {
}
The goal would be use to reuse the same name.
Maybe something using the by
keyword somehow? Composing the objects (where the problem here is that I have two abstract classes)Nezteb
10/02/2019, 8:39 PMmvn clean package
commands frequently time out with a “Java heap space” error when using maven-assembly-plugin
. Increasing my java/maven memory doesn’t fix it. I’ve added a single “hello world” type of Kotlin file, so I’m not sure why just adding the compiler for Kotlin pushes the entire build way over the edges.
Has anyone else hit this before when adding Kotlin to a Java project?tschuchort
10/02/2019, 9:39 PMCar
and promote it a BMW
or Toyota
by adding some values to it.Steve Young
10/02/2019, 10:56 PMMahendran
10/03/2019, 11:29 AMMahendran
10/03/2019, 11:29 AMkarelpeeters
10/03/2019, 12:25 PM