https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
announcements
  • d

    Deklan Webster

    04/13/2021, 10:21 PM
    new to kotlin. Is this https://blog.jetbrains.com/kotlin/2020/07/kotlin-native-memory-management-roadmap/ an going thing still? Where can I read about it?
    e
    • 2
    • 3
  • b

    Björn Mayer

    04/14/2021, 9:02 AM
    Hey, I have this Converter in Kotlin:
    class 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?
    p
    j
    • 3
    • 15
  • c

    Coen

    04/14/2021, 12:39 PM
    Hi, i want to send many web requests concurrently since sequentially they take like 5 minutes. Then combine the results and return them. What would be a good way of dealing with this?I read some things about coroutines, but havent got them working yet.
    r
    • 2
    • 3
  • n

    nfa

    04/14/2021, 1:06 PM
    Hi, are there suspendable alternatives to the standard functions ( let it run also apply with )? Something like
    suspend fun <T, R> T.let(block: suspend (T) -> R): R {
        return block(this)
    }
    e
    • 2
    • 1
  • k

    Kweku

    04/14/2021, 2:43 PM
    What is a good way to define a range of doubles that isn't inclusive of the last value. So I could for example define a range "a" zero up to 2.0, then have a range "b" from 2.0 to 4.0, then 2.0 would be part of b but not a. Basically how the until function worms for other Number types
    d
    m
    • 3
    • 4
  • b

    basher

    04/14/2021, 4:21 PM
    Hi! Where can I report feedback on the Kotlin 1.5.0-RC blog post?
    k
    l
    • 3
    • 7
  • s

    serebit

    04/14/2021, 5:01 PM
    What in the world was the justification for this?
    👍 1
    c
    n
    +4
    • 7
    • 41
  • b

    basher

    04/14/2021, 5:20 PM
    I’m trying to leave a Kotlin blog comment, but the POST request to comment returns 400 and says “comment contains restricted words”—tried removing various characters that I thought maybe were tripping it up. What am I missing?
    n
    n
    d
    • 4
    • 8
  • p

    Peter Ertl

    04/14/2021, 9:27 PM
    does anybody know if I can configure kotest in a way that some tests are disabled but can still be executed by manually launching them in IDEA? (I want to use these kind of “manual tests” for running custom code fragments during development)
    b
    s
    • 3
    • 4
  • p

    Peter Ertl

    04/14/2021, 9:39 PM
    is this supposed to work in kotlin-1.5.0-RC?
    @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’
    t
    a
    • 3
    • 2
  • t

    Tim Malseed

    04/15/2021, 12:34 AM
    Is there something similar to
    Collections.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
    }
    n
    e
    +2
    • 5
    • 42
  • p

    Paul Woitaschek

    04/15/2021, 7:03 AM
    I think something is severely wrong with 1.5.0-RC. https://github.com/PaulWoitaschek/KotlinBugSandbox/blob/c426f635c47751bde8450deed3d53359bd87b79f/src/commonTest/kotlin/MyTest.kt This just runs in M2 But if you bump it to 1.5.0-RC you end up with a very weird stacktrace I couldn't make sense of:
    kotlin.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)
    i
    • 2
    • 1
  • m

    Michael Böiers

    04/15/2021, 7:04 AM
    Good morning! I was wondering, is there a page/ticket/something else tracking the efforts to make Kotlin compatible with Java 16?
    i
    a
    • 3
    • 5
  • j

    jeggy

    04/15/2021, 9:22 AM
    I have someone trying to sign up for Kotlin Slack on kotlinlang.slack.com, but it seems like it is required to have a @jetbrains.com email? Is this true?
    k
    r
    • 3
    • 4
  • m

    mng

    04/15/2021, 3:25 PM
    Hey everyone. I have a function that looks like this:
    fun 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?
    m
    d
    e
    • 4
    • 9
  • t

    Travis Griggs

    04/15/2021, 3:49 PM
    Is the pattern
    someNullableExpression?.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.
    a
    d
    n
    • 4
    • 34
  • t

    Travis Griggs

    04/15/2021, 6:17 PM
    I'm guessing the answer is "no" to the following question: If I mark a class as open, is there anyway to make the default ACL for functions/properties in said class be open as well? Maybe there's some magical @Annotation thing where I can mark begin/end point where all declarations between are whatever?
    n
    c
    • 3
    • 2
  • i

    Ifvwm

    04/16/2021, 2:52 AM
    class 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?
    m
    • 2
    • 2
  • a

    Atchay Varma

    04/16/2021, 7:37 AM
    Hi mates, I want feedbacks from you guys, I am trying to build two tools which will make the search of solutions for errors during development by using some keyboard shortcuts and some cambased tech. I have already planned everything. But I found people saying stack overflow is going down and all are switching to discord servers like things. I will also accept it but, It will take some time right, And my question is are you still using stack overflow? Tell you reply then I may proceed to further development or I will quit that project..
    j
    • 2
    • 2
  • t

    thanksforallthefish

    04/16/2021, 9:19 AM
    not sure this should go here, and it does not seem strictly related to kotlin only, but has anyone seen something like (let me explain in a thread first though)?
    m
    g
    • 3
    • 7
  • u

    user

    04/16/2021, 3:45 PM
    message has been deleted
    🤘 2
    j
    n
    +8
    • 10
    • 22
  • c

    Chilli

    04/16/2021, 10:36 PM
    What do you guys prefer usually? (It's best if you pick the option you use when you don't need break/continue and don't “sequence” multiple extensions) 🔴 for-in loop
    for(element in collection) { ... }
    🔷 forEach extension
    collection.forEach { element -> ... }
    React with 🔴 or 🔷 to vote Feel free to reply and tell why you prefer that option
    🔴 17
    🔷 30
    n
    n
    +5
    • 8
    • 25
  • t

    Travis Griggs

    04/16/2021, 10:41 PM
    Is there a methodology I can use to instantiate a random subclass of a common/abstract superclass (all subclasses inherit the same constructor)? Or do I need to hardcode a list/when structure of subclass references to draw from?
    n
    u
    • 3
    • 2
  • a

    Adam S

    04/17/2021, 9:09 AM
    Is there a way to set a base .kts file as implementing an interface? I’m hacking around with deploying a .kts to Google Cloud Functions (for fun/the challenge). I can do it (define
    class 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 :)
    u
    • 2
    • 19
  • h

    Harry B

    04/17/2021, 5:10 PM
    Hey! Im looking into making a TCP Listener with Kotlin Native and wondered how to do that?
    g
    t
    • 3
    • 10
  • a

    Ananiya

    04/18/2021, 1:52 PM
    fun 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 btw
    y
    • 2
    • 8
  • f

    F0X

    04/18/2021, 5:20 PM
    Is it possible to get the containing class, if any, using reflections? so basically the opposite direction of
    nestedClasses
    ✅ 1
    n
    • 2
    • 3
  • a

    andrewreitz

    04/18/2021, 7:13 PM
    I made a dsl that can be used to configure my program, and is loaded using
    createJvmCompilationConfigurationFromTemplate
    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.
    n
    • 2
    • 3
  • m

    Marko Novakovic

    04/19/2021, 9:35 AM
    inline class can be declared as
    inline class
    and
    value class
    . why do both declarations exist? will one of them be dropped in stable release?
    a
    j
    • 3
    • 3
  • t

    Tomasz Krakowiak

    04/19/2021, 10:38 AM
    Why this is not allowed?
    public value class SetValue<Value>(public val value : Value)
    "Inline class cannot have value parameter of type 'Value'"
    y
    • 2
    • 1
Powered by Linen
Title
t

Tomasz Krakowiak

04/19/2021, 10:38 AM
Why this is not allowed?
public value class SetValue<Value>(public val value : Value)
"Inline class cannot have value parameter of type 'Value'"
y

Youssef Shoaib [MOD]

04/19/2021, 8:55 PM
The solution here is to use a concrete type of
Any?
and then make a factory function i.e. like this:
@JvmInline public value class SetValue<Value> internal constructor(private val _value : Any?) {
    public val value: Value get() = _value as Value
}
public fun <Value> SetValue(value: Value) = SetValue<Value>(value)
View count: 4