LastExceed
05/29/2021, 7:15 AMkotlin("jvm") version "1.5.10"
i'd just do kotlin("jvm") version "1.5.+"
afaik breaking changes only happen across major version updates so "auto bumping" the minor version should be fine ?Slackbot
05/29/2021, 7:27 AMJorkoh
05/29/2021, 12:43 PM// 18 minutes and 17.1 seconds => 1097.1 seconds => PT18M17.099999999S
val duration = 1097.1.toDuration(DurationUnit.SECONDS)
print(duration.toIsoString())
This loss of precision also exists if I use the toComponents
extension or inWholeX
accessorsLastExceed
05/29/2021, 10:01 PMDaniele Segato
05/30/2021, 12:24 PMReplaceWith
for this:
@Deprecated("Use BigDecimal for prices")
fun Double.formattedWithCurrency(locale: Locale = Constants.LOCALE): String {
return toBigDecimal().formattedWithCurrency(locale)
}
or for this constructor?
@Deprecated("Use the constructor with BigDecimal(s)")
constructor(
originalPrice: Double?,
price: Double,
locale: String,
percentage: Double?
): this(
originalPrice = originalPrice?.toBigDecimal(),
price = price.toBigDecimal(),
locale = locale,
percentage = percentage?.toBigDecimal()
)
carbaj0
05/30/2021, 4:32 PMMap<K,V>
using is Key?Ran Magen
05/30/2021, 7:12 PMLuigi Scarminio
05/31/2021, 1:27 PMPablo
05/31/2021, 2:07 PMdata class Foo (val id: String, val name: String)
val fooList = listof<Foo>(Foo("1","foo1"),Foo("2","foo22)
Imagine I get this fooList
as a parameter and I want to update this list, do I need to do a clone
of the list and then a copy
of the data class
and update there the values?
If i want to find first in the list of fooList if the id is equals 1 then change the "foo1" to another string is there any way to avoid to add an else? Otherwise the ide is complaining because I'm not using the result of copy.
fun whateverFun(list: List<Foo>, predicate: Int){
val foundValue = list.find{it.id == predicate}
foundValue?.let{
it.copy(title = "foo3"
}
}
The only way to avoid this warning is to do an if else of a map and in the else remain the same value as it was
I did it but I do not like tis..
list.map { example -> if(example.id == predicate){example.copy(title="foo3")}else{example.copy(it.title)}
Alexander Suraphel
05/31/2021, 5:06 PMLastExceed
05/31/2021, 6:45 PMhttps://i.imgur.com/NluduIk.png▾
Y
with either a String
or an X
seongsu kim
06/01/2021, 7:08 AMShabinder Singh
06/01/2021, 10:15 AMubu
06/01/2021, 1:12 PMsealed class GUIModel {
abstract val id: Id
interface Selectable {
val isSelected : Boolean
}
data class Model1(override val id: Id, override val isSelected: Boolean) : GUIModel(), Selectable
data class Model2(override val id: Id, override val isSelected: Boolean) : GUIModel(), Selectable
data class Model3(override val id: Id) : GUIModel()
}
is there a way to create a copy of the instance with updated isSelected
field? Without having to check the type:
fun GUIModel.createCopyWithUpdatedSelection(isSelected: Boolean) : GUIModel {
return when(this) {
is Model1 -> this.copy(isSelected = isSelected)
is Model2 -> this.copy(isSelected = isSelected)
is Model3 -> this
}
}
and without switching to var
in Selectable
interface.
Thanks!Tony
06/01/2021, 3:10 PMevaluateJavascript(...)
to set a javascript variable to a javascript object.
val javascriptString = "javascript: someString = {\"key\":\"value\"}"
webView.evaluateJavascript(javascriptString, null)
This is not working. Can someone point me in the right direction?carbaj0
06/01/2021, 4:00 PMfun <T> Collection<T>.plusHead(element: T): List<T> {
val result = ArrayList<T>(size + 1)
result.add(element)
result.addAll(this)
return result
}
Erik
06/01/2021, 7:28 PMWhen overriding your operator overloads, you can omit `operator`:(https://github.com/JetBrains/kotlin-web-site/blob/f3096d05fdfbc29ec4a704f42112028cdc7f48b7/docs/topics/operator-overloading.md#L15-L21) Why? Isn't it a bit implicit to override an operator, but not mark it as being an operator? I mean: if you'd override an operator without the keyword, you'd have to check the super declaration whether or not it actually is an operator. In turn, that can be an override without the keyword, all the way to the topmost declaration. I guess this is a non-issue because you wouldn't do this often. Without the explicit keyword it might be difficult to discover that a function is actually an
operator
, so that you could use the operator syntax instead of a regular function invocation (e.g. obj.invoke()
vs obj()
).LastExceed
06/02/2021, 7:30 AMLastExceed
06/02/2021, 9:33 AMrajendhiraneasu
06/02/2021, 11:42 AMval lbl = {txt:String -> txt.toCharArray()[0].toString()}
val username = "Rajendra prasad guru"
val initials = username.split(" ").let {
val l = lbl(it[0])
if(it.size>1) "$l${lbl(it[1])}" else l
}.toUpperCase()
println(initials)
Output is :RP
LastExceed
06/02/2021, 12:01 PMB
and D
here (other than the name) ? I've noticed that in B
i can use super.x
which i can't do in D
, but there doesn't seem to be any use in that since bot x
and super.x
point to the same variable
note: i know that A
technically doesn't need to be abstract
in this example. just assume that there's other abstract properties that require A
to be abstract
Colton Idle
06/02/2021, 4:14 PMLeoColman
06/02/2021, 8:02 PMpackage br.com.colman.dicehelper
import br.com.colman.dicehelper.br.com.colman.dicehelper.Dice
import org.antlr.runtime.ANTLRStringStream
public fun String.dice(): List<Dice> {
DiceNotationLexer(ANTLRStringStream(this))
return emptyList()
}
But the compiler warns me (via gradlew compileKotlin)
Type mismatch: inferred type is ANTLRStringStream but CharStream! was expected
ANTLRStringStream is a Java class, and it's definition is
public class ANTLRStringStream implements CharStream {
I assume that the "Type Mismatch" is wrong, as ANTLRStringStream is a CharStream, but it seems that the Kotlin compiler isn't very happy.
Does anybody know how what is going on here?Manuel Pérez Alcolea
06/02/2021, 8:23 PMopen class B() {
init {
println("Instance of B created!")
}
}
class A {
companion object Companion: B()
}
B's init
won't be called unless I access A
in any way, or create an instance of it (A.Companion
, A()
). So this isn't just like Java's static
(as the docs point out anyway: "Note that, even though the members of companion objects look like static members in other languages, *at runtime those are still instance members of real objects, and can, for example, implement interfaces*"). But this lazy-thing is something I wasn't expecting. Can I expect this behaviour no matter the platform?Ankit Dubey
06/03/2021, 9:53 AMval ktorHttpClient = HttpClient(OkHttp) {
engine {
}
I need OkHttp in my HttpClient.
This is in shared/commonMain.
But commonMain not able to access OkHttp.
If I add OkHttp in commonMain then getting build error.
implementation ("io.ktor:ktor-client-okhttp:$ktorVersion")
Failed building KotlinMPPGradleModel
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find ktor-client-okhttp-1.6.0-samplessources.jar (io.ktor:ktor-client-okhttp:1.6.0).
Slackbot
06/04/2021, 12:49 PMdead.fish
06/04/2021, 2:17 PMAbstractMethodError
when I try to call a fun interface
method with Kotlin 1.5:
// definition
fun interface OnItemClickListener {
fun onChannelClicked(channelId: ChannelId)
}
internal var clickListener: OnItemClickListener? = null
// callsite
holder.itemView.setOnClickListener {
clickListener?.onChannelClicked(channelId)
// ^^^ line 63, crash here
}
// Runtime crash
java.lang.AbstractMethodError: abstract method "void path.to.ChannelItemViewAdapter$OnItemClickListener.onChannelClicked-Grz9ttw(java.lang.String)"
at path.to.ChannelItemViewAdapter.onBindViewHolder$lambda-3$lambda-2(ChannelItemViewAdapter.kt:63)
at path.to.ChannelItemViewAdapter.lambda$CKDKaveMGRwL-cim-kOMtD1bOuU(Unknown Source:0)
// decompiled Kotlin
public interface OnItemClickListener {
void onChannelClicked_Grz9ttw/* $FF was: onChannelClicked-Grz9ttw*/(@NotNull String var1);
}
public final void onClick(View it) {
ChannelItemViewAdapter.OnItemClickListener var10000 = this.this$0.getClickListener$communication_debug();
if (var10000 != null) {
var10000.onChannelClicked-Grz9ttw(this.$this_with.getChannelId-WlYWy3A());
}
}
Any idea what the culprit might be here?Piyush Kukadiya
06/04/2021, 3:18 PMuser
06/04/2021, 4:33 PMturansky
06/04/2021, 6:39 PMtypealias
in different modules? Like this one:
package react
typealias FC<P> = FunctionalComponent<P>
turansky
06/04/2021, 6:39 PMtypealias
in different modules? Like this one:
package react
typealias FC<P> = FunctionalComponent<P>
Zach Klippenstein (he/him) [MOD]
06/04/2021, 7:04 PMturansky
06/04/2021, 7:31 PMandylamax
06/04/2021, 10:21 PMturansky
06/04/2021, 11:19 PMkqr
06/05/2021, 1:09 PMturansky
06/05/2021, 1:32 PMdmitriy.novozhilov
06/06/2021, 7:21 PM// MODULE: lib1
public class A {
public void foo() {}
}
// MODULE: lib2
public class A {
public void bar() {}
}
// MODULE: app (depends on lib1 and lib 2)
public class Main {
public static void test(A a) {
a.foo(); // (1)
a.bar(); // (2)
}
}
Which line ((1)
or (2)
) will be assumed as compile error? What happend on runtime if we comment errornous line?(1)
and it will be compiled successfully (because compilation classpath was lib2.jar;lib1.jar
) there is no guarantee that this code won't throw NoSuchMethodError
at runtime (where classpath can be lib1.jar;lib2.jar
)