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
  • i

    ivano

    01/11/2020, 9:15 PM
    in anyway I am trying anything, so my question is, can I transform the second parameter of
    getRecipes
    in a lambda?
    m
    • 2
    • 2
  • a

    Animesh Sahu

    01/12/2020, 11:47 AM
    Somebody saw my question https://kotlinlang.slack.com/archives/C0922A726/p1578555871055500 ?, is it better to create a new delegation class and implement in our way
    d
    • 2
    • 1
  • a

    Animesh Sahu

    01/12/2020, 12:33 PM
    How do i extract different data from the binary representation of an int? There are mode, sadc, badc, and gain(pg0, pg1), brng. I want to read/write them , and if possible change some binary digit, like changing 11th and 12th digits only or 8th 9th and 10th, and so on with/without reading/parsing like that.?
    k
    • 2
    • 2
  • t

    tipsy

    01/12/2020, 2:55 PM
    i'm trying to rewrite my test names which contain parens (like ``myMethod() works`()`) - is there a simple way of finding these tests?
    • 1
    • 1
  • a

    andyg

    01/12/2020, 6:15 PM
    is it possible to
    get
    the first of a list of possible keys from a map -- for example if the keys might not always be exact:
    personMap.getFrom("lastname", "LastName", "last_name", "nameLast")
    ?
    m
    • 2
    • 6
  • a

    A

    01/12/2020, 7:50 PM
    Can this be considered a Kotlin Vulnerability that if a
    var name=<lambda>
    is declared in a class, its returning value can be modified for a particular instance?This instance can be passed on to other functions which would end up with wrong data. I thought kotlin lambdas are supposed to be a clean looking replacement for functions, but functions do not change their logics. For eg:
    d
    d
    • 3
    • 3
  • a

    Arkadii Ivanov

    01/13/2020, 12:08 PM
    I'm wondering if there is a way to delegate an interface using
    by
    keyword and make all the delegated methods
    final
    . My use case is as follows:
    interface MyInterface {
        fun doSomething()
    }
    
    internal class MyInterfaceImpl : MyInterface {
        override fun doSomething() {
            // Do something here
        }
    }
    
    abstract class MyClass : MyInterface by MyInterfaceImpl() {
        abstract fun doSomethingElse()
    }
    
    class MyClassImpl : MyClass() {
        override fun doSomethingElse() {
            // Do something here
        }
    
        override fun doSomething() {
            // This override should be forbidden
            super.doSomething()
        }
    }
    d
    • 2
    • 2
  • j

    Jukka Siivonen

    01/13/2020, 12:53 PM
    I have a question about domain modeling and nullable fields, let's say I have (simplified example)
    data class Application(val applicantName: String?, val dateOfBirth: LocalDate?, val status: ApplicationStatus)
    m
    c
    • 3
    • 6
  • c

    CFrei

    01/13/2020, 2:46 PM
    "demo" is from https://kotlinlang.org/docs/reference/typecasts.html Can anyone please let me know why "demo2" is not working?
    Untitled
    e
    d
    • 3
    • 3
  • c

    Czar

    01/13/2020, 2:48 PM
    Just a raw thought:
    sealed class A
    
    class X : A()
    class Y : A()
    class Z : A()
    From what I've seen usually people do this to be able to write something like
    class Service {
      fun returnSomething(a: A) = when(a) {
        is X -> /* ... */
        is Y -> /* ... */
        is Z -> /* ... */
      }
    }
    Isn't it an illustration of an OOP anti-pattern, though? Shouldn't it have been something along the lines of:
    Service {
      fun returnSomething(a: A) = a.returnSomething()
    }
    Anytime you find yourself writing code of the form "if the object is of type
    T1
    , then do something, but if it's of type
    T2
    , then do something else," slap yourself!
    — Scott Meyers, Effective C++
    m
    b
    k
    • 4
    • 5
  • j

    Jan Shair

    01/13/2020, 4:24 PM
    Hey Guys I wrote this article few months ago. Hope it will help https://medium.com/tapdevs/part-1-clean-gradle-files-gradle-dependencies-group-bd9bb33c81cf
    🙏 1
    🚨 1
    a
    • 2
    • 1
  • s

    Sandy

    01/13/2020, 9:32 PM
    I am using kotlin with mysql. I have a string stored in mysql DB as : Apple's . However when I hit the rest api to read the string, it is displayed in logs as Apple \u2019. Why do my logs display the unicode character? Also on terminal, i see it as \u2019.
    b
    j
    w
    • 4
    • 9
  • i

    Iaroslav Postovalov

    01/14/2020, 1:25 PM
    Hello! Kotlin's framework design convention says to set visibility modifiers & return types explicitly. Should I do same in the tests of the library?
    s
    e
    • 3
    • 2
  • d

    Dominaezzz

    01/14/2020, 2:26 PM
    Is this a bug or am I missing something?
    fun <T> List<T>.idk(): List<T> = TODO()
    fun <T> List<T>?.idk(): List<T>? = TODO()
    
    fun lol() {
    	val real: List<String> = emptyList()
    	val empty: List<String>? = emptyList()
    	
    	real.idk() // Resolves the first function.
    	empty.idk() // Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type List<String>?
    }
    (Sorry about the names, they take up too much time to come up with) This only happens when the receiver is generic. The functions resolve as expected for
    String
    .
    m
    m
    • 3
    • 15
  • d

    dave08

    01/14/2020, 3:01 PM
    I need to know
    elapsedNow()
    from a time point that I receive from an api...
    m
    • 2
    • 3
  • b

    bod

    01/14/2020, 5:38 PM
    Hello, World! Hey, I often have functions of the form
    fooBar(a: Int? = null, b: String? = null, c: String? = null)
    where actually either a, b or c should be non null. Is there an idiomatic way to do this? I think Sealed classes would work, but a bit cumbersome. I've also seen people talking about an Either type (there's one in Arrow). Thoughts?
    d
    s
    • 3
    • 10
  • t

    taer

    01/14/2020, 7:10 PM
    Question on the kotlin-bom. It looks like the scopes aren't properly set in it.
    <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>kotlin-test</artifactId>
       <version>${kotlin.version}</version>
    </dependency>
    Same with kotlin-reflect(which I belive should be scope of
    reflect
    ). Is this intentional or an oversight?
    a
    • 2
    • 2
  • m

    magisu

    01/14/2020, 11:00 PM
    Quick stupid question... trying to learn Kotlin by coding some codewars challenges, and how to convert mutableListOf("abc", "def", "ghi").map { it.length } to an Array<Int>?
    u
    s
    • 3
    • 5
  • i

    iex

    01/15/2020, 3:22 PM
    How to idiomatically unwrap multiple optionals (without nesting)?
    r
    n
    • 3
    • 5
  • n

    Nikky

    01/15/2020, 5:51 PM
    does anyone know if coroutines and serialization libraries are gradle metadata compatible yet ?
    s
    s
    • 3
    • 2
  • a

    Alexjok

    01/16/2020, 8:50 AM
    Hello! How can i execute task at a specific time with Kotlin? Wich way is better?
    m
    s
    • 3
    • 3
  • s

    Slackbot

    01/16/2020, 9:45 AM
    This message was deleted.
    👎 1
    r
    a
    • 3
    • 2
  • a

    addamsson

    01/16/2020, 9:46 AM
    You can't be that desperate...
    d
    l
    • 3
    • 7
  • u

    ubu

    01/16/2020, 12:15 PM
    Hi there. I have a lot of ids across my android app, which are just strings. Would it be a good practice to use typealias in the following manner:
    typealias Id = String
    Thanks!
    r
    t
    • 3
    • 3
  • i

    iex

    01/16/2020, 1:56 PM
    In Kotlin's interfaces with default implementations, there's no way to constrain the interface to a specific implementation / access it, right? Edit: Here's a snippet in Swift of what I mean. I'm almost sure it's not possible in Kotlin, but just want to confirm (and see what alternative can be used)
    protocol ChildViewController where Self: UIViewController { // <--ChildViewController is "interface" and it's constrained to a specific class
    
        func foo()
    }
    
    extension ChildViewController {
    
        func foo() { <-- this is basically default interface implementation
            print(self.view) <-- here we access a field of the concrete type, i.e. UIViewController
        }
    
    }
    t
    e
    • 3
    • 4
  • g

    gian

    01/16/2020, 3:45 PM
    Is there a reason for the smart cast not happening when using
    .not()
    instead of
    !
    ?
    r
    s
    +2
    • 5
    • 5
  • v

    Vitali Plagov

    01/16/2020, 4:10 PM
    Does Kotlin have an option to get a list of all enums that are in a class. Not values, but names? I couldn’t find one. Then, through an extension function?
    l
    d
    • 3
    • 14
  • m

    MaHDi

    01/16/2020, 4:49 PM
    I have this code. How to make it jump out of while loop? I mean what should be input? I have entered nothing and just pressed the enter button but it takes it as string. And I also tried 0 and it did not work. "this line" never being printed to console. any ideas?
    fun main(args: Array<String>) {
        var line = readLine()
        while (line !=null) {
            println(line)
            line = readLine()
        }
        println("this line")
    }
    m
    s
    • 3
    • 3
  • g

    Gregor Zeitlinger

    01/16/2020, 4:58 PM
    Is there a policy how long the kotlin runtime is supported, similar to the jdk support policy?
    a
    • 2
    • 2
  • s

    Sylvain Patenaude

    01/16/2020, 5:44 PM
    message has been deleted
    c
    • 2
    • 4
Powered by Linen
Title
s

Sylvain Patenaude

01/16/2020, 5:44 PM
message has been deleted
c

Casey Brooks

01/16/2020, 5:48 PM
You should be able to use
@file:JvmName("Name3")
to change the name of the generated class for the top-level functions https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#package-level-functions
👍 1
s

Sylvain Patenaude

01/23/2020, 9:16 PM
It works well for Android/Jvm clients, but it doesn't solve the "issue" for an iOS consumer. It still remains Name3Kt.function1(). 🙁 Is there a way similar to
@file:JvmName("Name3")
for iOS or should I go back to putting my functions in an
object
named "Name3"?
It looks like even with an
object
named "MyObject" for instance, a call from iOS (Swift for instance) would look like this: MyObject*Kt*.function()
I can't believe there's nothing similar to
@file:JvmName("CustomName")
for iOS. Now when documenting my SDK, I need 2 different APIs for Android and iOS: • Android: MyObjectName.someFunction() • iOS: MyObjectName*Kt*.someFunction() This is really annoying.
View count: 2