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
announcements
  • r

    robstoll

    04/06/2018, 12:55 PM
    is there a way to escape $ in a triple quote string?
    i
    • 2
    • 2
  • s

    Shawn

    04/06/2018, 1:04 PM
    @dekans the java way, probably
    private val _list: MutableList<T>
    val list: List<T> = _list
    a
    • 2
    • 1
  • j

    Jeevan

    04/06/2018, 2:34 PM
    https://kotlinlang.slack.com/archives/C0922A726/p1523019871000373
    s
    g
    • 3
    • 5
  • j

    jw

    04/06/2018, 3:13 PM
    once you know the rules the behavior should be obvious. it's equally troublesome in Java. the API design is setting you up for failure
    👆 3
    👍 2
    v
    • 2
    • 1
  • s

    Shawn

    04/06/2018, 3:54 PM
    but, uh, how young are we talking?
    a
    p
    • 3
    • 6
  • a

    andreworobator

    04/06/2018, 6:42 PM
    fun bindView(
        position: Int,
        view: ListItemView // Interface
      ) = when (ViewTypeEnum.values()[position]) {
        ENUM1 -> bindViewType1(view as ViewType1)
        ENUM2 -> bindViewType2(view as ViewType2)
      }
    a
    l
    • 3
    • 14
  • a

    andreworobator

    04/06/2018, 6:58 PM
    This is the pattern I’m following: https://android.jlelse.eu/recyclerview-in-mvp-passive-views-approach-8dd74633158
    m
    • 2
    • 1
  • m

    makarezp

    04/06/2018, 8:04 PM
    I’d like to start contributing to kotlin, any advice?
    a
    i
    +2
    • 5
    • 10
  • m

    muralimohan962

    04/07/2018, 6:41 AM
    Why doesn't Kotlin have any keyword like synchronized for synchronization? Why do they ask us to use @Synchronized annotation?
    e
    • 2
    • 2
  • b

    barteks2x

    04/08/2018, 7:14 PM
    is there a way to do this without making my own class?
    class LazyToString(val obj: () -> Any) {
        override fun toString(): String {
            return obj().toString()
        }
    }
    
    thing = LazyToString { doThing() }
    r
    • 2
    • 3
  • p

    pakoito

    04/08/2018, 7:55 PM
    how do you
    @parameter
    refer to the type the extension is in?
    g
    • 2
    • 4
  • g

    gildor

    04/09/2018, 2:48 AM
    moshi doesn’t throw by default, you need kotshi for that: https://github.com/ansman/kotshi
    e
    • 2
    • 2
  • p

    pike

    04/09/2018, 4:24 AM
    I changed it to strings: for (i in 1..101) println(“${if(i%3 == 0) “fizz” else “”}${if(i%5==0) “buzz” else i.toString()}“)
    n
    • 2
    • 2
  • d

    diesieben07

    04/09/2018, 8:22 AM
    Which is essentially a union type
    g
    • 2
    • 1
  • m

    mzgreen

    04/09/2018, 8:22 AM
    you’re right, they are often used with aliases though
    g
    • 2
    • 2
  • l

    louiscad

    04/09/2018, 9:05 AM
    @gildor I just thought about renaming a class in a library, and I thought I can use a deprecated typealias for the old name to keep source compatibility (not binary though). Also, I had to replace Google Maps by MapBox in a project, MapBox being basically a copy pasted API, with some differences, and some extra/missing features, and I thought I could use a typealias to swap one with another anytime.
    g
    • 2
    • 1
  • j

    jakubgruber

    04/09/2018, 9:25 AM
    What is difference between
    @JvmField
    and
    const
    ? Is property exposed to Java as a static if
    const
    is used? Android Studio recommended that to me, so just asking 🙂
    e
    • 2
    • 1
  • m

    marstran

    04/09/2018, 10:36 AM
    The
    copy
    function only copies the constructor parameters. You should do this:
    data class Person(val name: String = "Tristan", val age: Int = 1)
    
    fun main(args: Array<String>) {
        val person = Person()
        val personCloned = person.copy(age = 3)
        println(personCloned.age)
    }
    t
    a
    • 3
    • 2
  • a

    adams2

    04/09/2018, 2:06 PM
    how do I debug kapt itself
    g
    • 2
    • 3
  • a

    adams2

    04/09/2018, 2:06 PM
    it's crashing with an NPE at some sun.* packages
    g
    • 2
    • 1
  • j

    Jacks0n23

    04/09/2018, 2:13 PM
    Are i understand something wrong or it's kotlin bug? I have : data class Foo ( val initializationType: InitializationType) { val isInitDefault = initializationType == InitializationType.Default } and when i call this val it's working incorrect, but when i transform it to fun or just add custom get() = initializationType == InitializationType.Default it start working like it should what the problem? P.S. InitializationType it's enum
    h
    • 2
    • 1
  • k

    karelpeeters

    04/09/2018, 7:27 PM
    Can you give an example of such a context?
    r
    • 2
    • 1
  • m

    makarezp

    04/09/2018, 7:47 PM
    Hi, I am trying to work on Kotlin source on idea ultimate, I have followed the instruction from readme.md, I’ve opened project, added the module from existing sources, but it seems that idea can’t resolve dependencies in build.gradle.kts. All gradle builds are working properly. So if I run ./gradlew coreLibTest it’s compiling and running, but if I try to run tests from idea I’m getting errors. I’ve got 2018.1 build.
    k
    • 2
    • 1
  • h

    Hemanth

    04/10/2018, 7:02 AM
    HI, any references to read credit card number from camera?
    🤦 2
    :stackoverflow: 9
    f
    • 2
    • 2
  • t

    Tarun

    04/10/2018, 9:17 AM
    Hey I am working on a library in Kotlin In this library, if I have some variable inside
    companion object
    , than those variable are treated as static in Java But when I try to access those variable in a java project, which is using library, It is like :
    MyClass.Companion.abcVariable
    I searched and found I had to append @JvmStatic in front of variable so that java can access it directly like :
    MyClass.abcVariable
    This works for
    classes
    but for
    interfaces
    it requires a min API level of 24 and my Min API level is 21 Is there any other way to directly access companion object variables for
    interface
    in API projects supporting min API level less than 24 like :
    MyClass.abcVariable
    c
    • 2
    • 2
  • r

    Rich Gabrielli

    04/10/2018, 8:32 PM
    Thanks for the explanation, but I am a bit confused. I am new to Kotlin and Slack. If not in general or android, should it be getting started? I do not see a stackoverflow
    g
    • 2
    • 1
  • p

    pavel

    04/10/2018, 9:39 PM
    or you could add a
    by Delegates.notNull()
    ➕ 1
    a
    • 2
    • 9
  • e

    edwardwongtl

    04/11/2018, 3:48 AM
    Is there a way to limit function invocation using something like
    fun doSth(action: Mode.() -> Unit)
    ? But
    Mode
    contains only functions, no properties. Although it is completely fine to create instance of
    Mode
    and pass it to
    action(mode)
    , it just doesn't quite make sense for me to create such a instance.
    g
    • 2
    • 12
  • l

    louiscad

    04/11/2018, 8:13 AM
    I do not have experience in writing in C# at the moment, but it seems like this language is a bit more verbose than Kotlin, hence my question. I got interested in developing on Unity 3D since I saw Google Maps gaming API is coming. I guess I'll try with C# when time comes to play with it then, thank you
    b
    • 2
    • 2
  • j

    Jon

    04/11/2018, 9:37 AM
    Is it possible to constrain a List guaranteeing that it always contains at least one element? Currently I use
    require
    in
    init
    of the class it's in, but the compiler doesn't know that this invariant exists so still requires null-safety checks.
    k
    a
    +2
    • 5
    • 4
Powered by Linen
Title
j

Jon

04/11/2018, 9:37 AM
Is it possible to constrain a List guaranteeing that it always contains at least one element? Currently I use
require
in
init
of the class it's in, but the compiler doesn't know that this invariant exists so still requires null-safety checks.
k

karelpeeters

04/11/2018, 9:51 AM
I don't think that's possible unfortunately.
a

Andreas Sinz

04/11/2018, 12:30 PM
What null-safety check are you refering to?
s

SiebelsTim

04/11/2018, 1:20 PM
build your own list-type, that needs at least one element in the constructor
g

gildor

04/11/2018, 3:55 PM
For example of such non empty list implementation you can take a look on NonEmptyList from Arrow https://github.com/arrow-kt/arrow/blob/master/modules/core/arrow-data/src/main/kotlin/arrow/data/NonEmptyList.kt
View count: 1