https://kotlinlang.org logo
Docs
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
getting-started
  • k

    Konstantin Petrukhnov

    05/03/2018, 10:21 AM
    Could you suggest DI (or something similar)? E.g. code example. Should work on iOS. I want to have static class/object/whatever, that I could access from other classes. This static class needs initialization (passing object, done once). I don't want to pass its reference everywhere.
    a
    p
    • 3
    • 2
  • u

    ursus

    05/06/2018, 2:19 AM
    Hi guys, what are acutal good usecases for run, let, apply, also? Or is it just a hipster thing
    a
    • 2
    • 1
  • u

    ursus

    05/06/2018, 12:11 PM
    yea i do get when you assign to a property, or when you need a expression, but other than that im not sold on it, "?.let { }" why not just if != null
    a
    s
    • 3
    • 9
  • h

    halirutan

    05/07/2018, 5:29 AM
    if (element is SetDelayed || element is TagSetDelayed || element is Set || element is Condition)
    🇳🇴 1
    r
    • 2
    • 2
  • h

    halirutan

    05/08/2018, 2:09 AM
    @nil2l @karelpeeters Thanks. I tried already a
    listOf
    solution and it didn't work because of inheritance. Well, I guess then the simple
    is
    solution is directly readable and I stick to this. Thanks for your efforts 🙂
    s
    n
    k
    • 4
    • 6
  • d

    dave08

    05/08/2018, 1:02 PM
    I have list1 that I need to associate to list2 one-to-one, is there an ideomatic way to do this?
    s
    • 2
    • 7
  • b

    bjonnh

    05/10/2018, 12:08 AM
    where datapoint:
    @Serializable
    data class DataPoint (
            val name: String,
            val value: Double
    )
    s
    • 2
    • 7
  • d

    Daniel

    05/10/2018, 7:49 AM
    Hey guys, Im new to this community. I have been working on kotlin since more than a year. I was trying to implement codestyling using detekt. It worked for me perfectly. so, I came up with an article which might help you. Thanks to @Artur Bosch for this awesome library. https://medium.com/@danielvivek2006/code-styling-for-kotlin-fa7a8291c254
    👍 1
    n
    • 2
    • 2
  • a

    Amadiro

    05/11/2018, 4:09 PM
    Hey, probably a dumb question, but I've never worked with kotlin before; I just created a new kotlin project in intellij, and now I want to add an external project to it (https://github.com/xenomachina/kotlin-argparser for instance). How do I go about this? Do I have to add a gradle file or somesuch?
    n
    a
    • 3
    • 7
  • a

    Ayden

    05/13/2018, 1:24 AM
    @araqnid Some of them really hard to understand. I don't know what does the tutorial want to achievement. Instead of spending time to code the solution, I spent more time on reading the instruction.
    i
    • 2
    • 1
  • a

    Andreas Sinz

    05/14/2018, 8:51 PM
    @kiptoo your
    Box<T>
    is invariant, that means
    Box<Int>
    is not a subtype of
    Box<Number>
    https://proandroiddev.com/understanding-generics-and-variance-in-kotlin-714c14564c47
    k
    • 2
    • 4
  • j

    jlepper

    05/15/2018, 10:08 PM
    Hi. I'm working with a team (and am myself) new to the JVM, Kotlin, and Rat Pack. I'm looking for any tutorials on how one goes about mocking outgoing http calls in tests.
    s
    a
    • 3
    • 2
  • h

    holgerbrandl

    05/16/2018, 6:41 AM
    @Sudhir Singh Khanger @Hamza String is final and can’t be extended. But even if it would be flagged as
    open
    you would need to write
    ) : String()
    to call its constructor. The
    ()
    are not necessary when implementing an interface.
    h
    • 2
    • 1
  • h

    Hamza

    05/17/2018, 3:17 PM
    @Andreas Sinz it’s using JDA, which is a discord Bot API, and KUtils, which is a kotlin dsl for the command and stuff to make life easier
    a
    • 2
    • 1
  • x

    xenoterracide

    05/17/2018, 11:22 PM
    I don't know if that makes me happy or sad... if if was an object, or function that took a lambda...
    r
    • 2
    • 1
  • m

    Manoj

    05/18/2018, 1:39 PM
    any book / tutorials which walks through a backend project and teaches kotlin ?
    ➕ 2
    p
    • 2
    • 2
  • k

    karelpeeters

    05/19/2018, 7:39 AM
    Yup, the problem is that those fields are vars, so it's ambiguous whether to add to the existing collection or create a new one and put it in
    x
    .
    b
    a
    • 3
    • 13
  • t

    Tyler

    05/22/2018, 3:29 PM
    Hi, I keep seeing intents with java classes as an argument, but I'm not sure how to use a Kotlin one instead?
    val i = Intent(this, ExampleJavaClass::class.java)
    k
    a
    • 3
    • 6
  • m

    menegatti

    05/24/2018, 7:08 AM
    but as the accepted answer explains, it’s really hard to provide the data class sugar (equals, hashcode, copy) when there’s inheritance involved
    b
    • 2
    • 1
  • a

    arekolek

    05/24/2018, 1:53 PM
    I think you meant
    Bar.() -> Unit
    @menegatti
    m
    • 2
    • 1
  • r

    rook

    05/25/2018, 7:38 PM
    Just doing a sanity check
    when(e) {
      is String, Int -> /*do stuff*/
    }
    It doesn’t appear that I can accomplish the above. Is that correct?
    b
    • 2
    • 5
  • h

    Hamza

    05/27/2018, 2:46 AM
    operator fun invoke(args: EmbedDSLHandle.() -> Unit) {}
    k
    • 2
    • 2
  • h

    Hamza

    05/27/2018, 2:46 AM
    one more question, how do I make a function that returns nothing without throwing an Exception?
    a
    k
    o
    • 4
    • 6
  • j

    Javal

    05/27/2018, 2:21 PM
    I am new to kotlin, our team is thinking of utilizing kotlin for writing one of the service for our project. Is ktor a good framework to go with or there are any better alternatives?
    o
    • 2
    • 2
  • k

    Krizzu

    05/29/2018, 8:19 AM
    Hey guys, got a question about typing in Kotlin - I don’t especially know what what this typing means
    Int.() -> Unit
    . I get it’s a function, but this
    ClassName + dot
    is strange for me
    m
    s
    e
    • 4
    • 7
  • m

    Manthan

    05/29/2018, 1:50 PM
    I am doing Kotlin Koans exercises and it does say that it should be written. In an exercise of nullable and non nullable types.
    a
    • 2
    • 2
  • b

    B_P

    05/31/2018, 7:36 AM
    hi, I wanted to do all checks using when so my function takes one argument as Int and another one as Int, in the body of the function I do the sum of two and I wanted to use when like so "fun abc(size : Int, x : Int)" when(sum) { is bigger than size -> return false is it possible to make "is bigger than" in when condition?
    s
    • 2
    • 3
  • r

    Rak

    05/31/2018, 9:56 AM
    (Any) is not compatible with (List<Int>) or (Int)
    k
    • 2
    • 2
  • a

    Andreas Sinz

    05/31/2018, 12:21 PM
    @poohbar I'd use `var`s with a private setter and a
    fun changeName(first, last)
    👍 1
    p
    a
    • 3
    • 14
  • o

    otakusenpai

    05/31/2018, 12:29 PM
    then i tried the equals(Any?) function
    a
    • 2
    • 10
Powered by Linen
Title
o

otakusenpai

05/31/2018, 12:29 PM
then i tried the equals(Any?) function
a

Andreas Sinz

05/31/2018, 12:30 PM
what does
println(msg.retSender() == this.name)
print?
o

otakusenpai

05/31/2018, 12:32 PM
Result = false println("Result = ${msg.retSender() == this.name}")
a

Andreas Sinz

05/31/2018, 12:36 PM
now you know that both strings are NOT the same
check for trailing spaces, tabs or newlines
o

otakusenpai

05/31/2018, 12:36 PM
how
a

Andreas Sinz

05/31/2018, 12:38 PM
easiest way is to surround the strings you output with
"
for example
println("Msg.retSender() = '${msg.retSender()}'")
o

otakusenpai

05/31/2018, 12:40 PM
'##ChatterZ '
a

Andreas Sinz

05/31/2018, 12:40 PM
there you have it, one space at the end of the string
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-end.html
o

otakusenpai

05/31/2018, 12:41 PM
yeah
View count: 1