Deklan Webster
04/13/2021, 10:21 PMBjörn Mayer
04/14/2021, 9:02 AMclass ExampleConverter<T> : Converter<T, String> {
override fun convert(source: T): String? {
TODO("Not yet implemented")
}
}
it implements this Java interface:
@FunctionalInterface
public interface Converter<S, T> {
/**
* Convert the source object of type {@code S} to target type {@code T}.
* @param source the source object to convert, which must be an instance of {@code S} (never {@code null})
* @return the converted object, which must be an instance of {@code T} (potentially {@code null})
* @throws IllegalArgumentException if the source cannot be converted to the desired target type
*/
@Nullable
T convert(S source);
}
The IDE says, that everything is fine.
However when I try to compile I get:
Class 'ExampleConverter' is not abstract and does not implement abstract member public abstract fun convert(p0: T!!): String?
'convert' overrides nothing
Any idea?Coen
04/14/2021, 12:39 PMnfa
04/14/2021, 1:06 PMsuspend fun <T, R> T.let(block: suspend (T) -> R): R {
return block(this)
}
Kweku
04/14/2021, 2:43 PMbasher
04/14/2021, 4:21 PMserebit
04/14/2021, 5:01 PMbasher
04/14/2021, 5:20 PMPeter Ertl
04/14/2021, 9:27 PMPeter Ertl
04/14/2021, 9:39 PM@JvmInline
@Serializable
value class ProductId(val value: Int)
I get a huge stack trace with kotlinx.serialization when trying this
I use:
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.1.0")
above code works when using ‘inline class’ but I get a deprecation warning from the compiler that it will be replaced by ‘value class’Tim Malseed
04/15/2021, 12:34 AMCollections.groupBy
that allows you to specify a grouping function?
I have a list of Songs. I’d like to group them together, using the following logic (psuedo-code)
val group = if (album name matches) {
if (artist name matches) {
true
} else {
if (album-artist name matches) {
true
}
}
false
}
Paul Woitaschek
04/15/2021, 7:03 AMkotlin.time.DurationKt.getNanoseconds(J)D
java.lang.NoSuchMethodError: kotlin.time.DurationKt.getNanoseconds(J)D
at kotlinx.datetime.DateTimeUnit$TimeBased.<init>(DateTimeUnit.kt:54)
at kotlinx.datetime.DateTimeUnit.<clinit>(DateTimeUnit.kt:108)
at MyTest.test(MyTest.kt:8)
Michael Böiers
04/15/2021, 7:04 AMjeggy
04/15/2021, 9:22 AMmng
04/15/2021, 3:25 PMfun getMyResult(): Result<TheThing>{
var myResult = Result.success(TheThing())
return myRresult.mapCatching {
throw IllegalArgumentException("")
}
}
My expectation here is that the getMyResult()
function will return a Failure Result that wraps the IllegalArgumentException. However, what is happening is that my application just crashes. Am I misunderstanding how mapCatching
works?Travis Griggs
04/15/2021, 3:49 PMsomeNullableExpression?.let { thing -> thing.doStuff() } ?: run { otherwiseBehavior() }
a widely used pattern in Kotlin? I've been using it quite a bit when I port Swift code, because it's the closest (I thought) equivalent to Swift's if let thing = someNilableExpression { thing.doStuff } else { otherwiseBehavior()
. But I've found edge cases where there are surprises, and so I've been rethinking whether I should be using it so much.Travis Griggs
04/15/2021, 6:17 PMIfvwm
04/16/2021, 2:52 AMclass DownloadStructure(val name: String, val link: String, val size: Int) {
fun fmap (f: (String) -> String): DownloadStructure = DownloadStructure(name, f(link), size)
} // why this would cause class Redeclaration error?
Atchay Varma
04/16/2021, 7:37 AMthanksforallthefish
04/16/2021, 9:19 AMuser
04/16/2021, 3:45 PMhttps://pbs.twimg.com/media/EzGzm5fW8AQPZ08.jpg▾
Chilli
04/16/2021, 10:36 PMfor(element in collection) { ... }
🔷 forEach extension
collection.forEach { element -> ... }
React with 🔴 or 🔷 to vote
Feel free to reply and tell why you prefer that optionTravis Griggs
04/16/2021, 10:41 PMAdam S
04/17/2021, 9:09 AMclass Operator : HttpFunction
in Main.kts, compile to .jar, then in GCF set the target to main.Main$Operator
), but I don’t like that $
. So if the .kts could implement the interface, then my minor annoyance would be cured. Or if it’s not possible, at least my curiousity eased :)Harry B
04/17/2021, 5:10 PMAnaniya
04/18/2021, 1:52 PMfun interface MCall2{
fun updateMyText(text: String)
}
class Testing : MCall2 {
var st: String? = null
override fun updateMyText(text: String){
st = text
}
init {
print(st)
}
}
@Test
fun check_the_call_back(){
Testing().updateMyText("trying to re assign")
}
I was trying to reassign st
value with in SAM is it possible tho , this returns null btwF0X
04/18/2021, 5:20 PMnestedClasses
andrewreitz
04/18/2021, 7:13 PMcreateJvmCompilationConfigurationFromTemplate
is there a way to tell the ide anything about my script files in order to get code highlighting?
I know there is the ide
block, but I’m not sure how that would be able to tell Intellij about my code.Marko Novakovic
04/19/2021, 9:35 AMinline class
and value class
. why do both declarations exist? will one of them be dropped in stable release?Tomasz Krakowiak
04/19/2021, 10:38 AMpublic value class SetValue<Value>(public val value : Value)
"Inline class cannot have value parameter of type 'Value'"