magnumrocha
03/21/2022, 9:15 AMursus
03/22/2022, 12:31 AMchristophsturm
03/22/2022, 2:09 PMTim Malseed
03/23/2022, 11:36 PMPhilipp Mayer
03/25/2022, 10:00 AMdata class MyDomainObject(val message: String)
//some adapter package
data class MyResponse(val localizedMessage: String)
fun MyDomainObject.toMyResponse(locale: Locale) : MyResponse {
/* imagine a lot of mapping here, calling other pure functions in the same file */
return MyResponse(this.message + locale.toString())
}
It’s a complex object, so placing the extension function inside the MyResponse
file would hinder readability.
I couldn’t really find anything regarding that in the kotlin docs.
What’s your take on it? I would love to hear different opinions!magnumrocha
03/31/2022, 8:49 AMAlex
03/31/2022, 10:40 AMrtsketo
03/31/2022, 4:55 PMopen class A {
open fun somFun(lambda: (suspend A.() -> Unit)? = null) = apply { /* ... */ }
}
class B : A()
class C {
/**
* Type mismatch.
* Required: B
* Found: A
*/
val b: B = B().somFun { }
}
Is there a way to return B instead of A in B().somFun { }
without using a static function like below?
open class A {
companion object {
fun <T : A> T.somFun(lambda: (suspend T.() -> Unit)? = null) = apply { /* ... */ }
}
}
Like, is there a way to have <out A> in a lambda?Slackbot
04/01/2022, 7:33 AMJason5lee
04/02/2022, 2:07 PMtherealbluepandabear
04/03/2022, 3:45 AMSlackbot
04/06/2022, 5:15 AMsuresh
04/06/2022, 5:07 PMpablisco
04/08/2022, 11:13 AMsamp
04/09/2022, 4:14 PMsealed class PowerTool(
@JvmField open val name: String,
@JvmField open val price: Double
) {
data class CircularSaw(
val diameter: Int,
val cordless: Boolean,
override val name: String,
override val price: Double
) : PowerTool(name, price)
data class DrillPress(
val rpm: Int,
override val name: String,
override val price: Double
) : PowerTool(name, price)
}
Error: JvmField can only be applied to final property
My requirement for jvm field is: I need @JvmField for java consumers as I don’t want to refactor the code to use the setter/getter method and want to use as a field.
Any thoughts?Jason5lee
04/12/2022, 2:52 AMsindrenm
04/12/2022, 1:46 PMinline fun foo() = bar() // does not compile
private inline fun bar() {}
Jason5lee
04/15/2022, 3:15 PMChaiwa Berian
04/16/2022, 4:20 PMoshai
04/20/2022, 1:07 PMtherealbluepandabear
04/21/2022, 5:53 AMtherealbluepandabear
04/21/2022, 5:57 AMFrancis Mariano
04/25/2022, 12:57 PMdarkmoon_uk
04/27/2022, 2:41 AMSam
04/28/2022, 8:42 AMtherealbluepandabear
05/03/2022, 2:03 AMColton Idle
05/06/2022, 4:33 PMrtsketo
05/12/2022, 11:29 AMColton Idle
05/13/2022, 4:43 AMjmfayard
05/13/2022, 4:05 PM