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

    gabrielfv

    07/03/2018, 7:50 PM
    So, currently, there is no option for if I want to define that an Interface method should return either one class or some other, right? Type composition like:
    typealias SourceOrFactory<T> = List<T> | DataSource.Factory<T>
    c
    l
    +3
    • 6
    • 17
  • n

    Nikky

    07/05/2018, 1:51 AM
    is your
    =
    super thin in in the screenshot or are those
    -
    ? and i am not sure if its a proper replacement but there is StringBuffer too and StringBuilder should still exist.. maybe your gradle setup is incorrect or just broken during switch to 1.2
    l
    c
    • 3
    • 3
  • e

    eliasaj

    07/05/2018, 12:41 PM
    If I don't know Java(and don't care to learn to learn it), and I want to learn Kotlin and know its best practices, what are some good resources? I don't necessarily want to do Android either. I actually want to do more server side stuff.
    k
    m
    • 3
    • 6
  • i

    Ivan

    07/07/2018, 10:39 PM
    Hi, guys, is there any reliable tutorial for kotlin/native? Like video, or something, the official docs are not helping at all
    k
    • 2
    • 1
  • u

    unnsse

    07/09/2018, 2:19 AM
    Am wondering how to setup the ≠ in IntelliJ IDEA. I downloaded the following Fonts: Hasklig and Monoid… Have FiraCode already installed. When I do this in my Kotlin code !=, how to turn that into ≠ ?
    🤔 1
    b
    n
    • 3
    • 2
  • b

    benleggiero

    07/09/2018, 3:20 AM
    Is this a bug or intended behavior?
    class Foo {
        companion object
    }
    
    typealias Bar = Foo
    
    fun Foo.Companion.hoge() = "hoge" // Okay
    fun Bar.Companion.qux() = "qux" // ERROR: Unresolved reference: Companion
    k
    h
    • 3
    • 4
  • f

    forcelain

    07/09/2018, 6:08 PM
    does “+” in
    mylist + newElement
    make a new list?
    :yes: 2
    r
    u
    k
    • 4
    • 3
  • h

    HaSH

    07/10/2018, 6:41 PM
    Hey all! I'm wondering how I can have kotlin "automagically" include a val from a data class in it's generated code? Pseudo code: https://paste.ubuntu.com/p/5tVKgwNTvM/
    r
    • 2
    • 1
  • h

    HaSH

    07/10/2018, 6:43 PM
    I want a simple data class that I can use like: Sensor(localDateTime, TEMP, RH) to create the object. But every object should also have the temperature in F automatically calculated and available.
    s
    • 2
    • 1
  • v

    vvl

    07/10/2018, 7:38 PM
    @HaSH you can use something like
    data class Test(val test1: Int, val test2: Int, private val test3: Int = test2 * test1)
    r
    s
    • 3
    • 2
  • e

    edwardwongtl

    07/11/2018, 7:39 AM
    map[key]?.let { f(it) } ?: init
    v
    • 2
    • 2
  • r

    Rak

    07/11/2018, 10:06 AM
    Soo many options for unit testing, is there a combination that seems to be more popular?
    i
    • 2
    • 1
  • n

    Nikolai

    07/14/2018, 4:40 AM
    Hello, Everyone I am trying Kotlin-Native because I am very interesting in creating multiplatform apps for iOS and Android. As soon as Kotlin-Native become available I tried to setup multiplatform project with common code module. - I created a Kotlin (Multiplatform-Experiment) project with IDEA. It had two platform specific modules - jvm (for Android) and js (I just ignore it) and common module. - Created new project in Android Studio and imported common and jvm module from previous step - Implemented project for android side. All UI code is in Android Studio project, code that supposed to be common - in common module. For logic that supposed to be platform specific common module use expect class syntax and those classes implemented in jvm module. Now, I wanted to implement iOS part in AppCode. How I should import common module and implement platform specific logic? Or maybe I am doing it all wrong and multiplatform project should be implemented using different flow? I tried to look into Spinner App from Kotlin Conference, but it's so big for me where are many parts and I can't understand how to implement only two projects for client-side. Thanks for your help.
    a
    • 2
    • 2
  • o

    oday

    07/17/2018, 7:53 AM
    hey guys, I know it’s silly but is there something neater than this 🙂
    fromPriceValueET.typeface = Typeface.createFromAsset(
                assets, "fonts/Sofia Pro Bold.otf"
            )
    
            toPriceValueET.typeface = Typeface.createFromAsset(
                assets, "fonts/Sofia Pro Bold.otf"
            )
    
            budgetCurrencyTV.typeface = Typeface.createFromAsset(
                assets, "fonts/Sofia Pro Bold.otf"
            )
    d
    • 2
    • 4
  • a

    Aregev2

    07/17/2018, 12:34 PM
    Created that real quick, hope it helps... https://gist.github.com/AregevDev/a848edce3d11a40852f5abbfdb45a700
    n
    • 2
    • 1
  • b

    bruno.aybar

    07/17/2018, 2:41 PM
    Hi! For the folks getting started with Kotlin, I recently wrote this post about annotations. Feedback is welcome! https://medium.com/@bruno.aybar/annotations-for-your-java-friendly-kotlin-code-badfbedec14
    d
    r
    • 3
    • 6
  • s

    Sudhir Singh Khanger

    07/18/2018, 2:31 AM
    fun diskIO(): Executor = diskIO
    
        fun diskIO(): Executor {
            return diskIO
        }
    Are these two syntax doing the same thing?
    :yes: 9
    n
    k
    • 3
    • 4
  • a

    ahegazy

    07/18/2018, 12:32 PM
    there is no oneach! Can you pass on the documentation?
    l
    e
    • 3
    • 4
  • a

    Andreas Sinz

    07/18/2018, 2:06 PM
    but doesn't exist in the context of an RX
    Observable
    k
    • 2
    • 1
  • a

    Aregev2

    07/18/2018, 8:10 PM
    Above, messing with specific situations
    k
    • 2
    • 2
  • a

    Aregev2

    07/18/2018, 8:16 PM
    Maybe a proposal will speed things up
    k
    • 2
    • 1
  • s

    Sudhir Singh Khanger

    07/19/2018, 3:12 AM
    The classes doc mentions the following rule.
    If the constructor has annotations or visibility modifiers, the constructor keyword is required
    I don't see it being followed in the Google sample.
    @Singleton
    open class AppExecutors(
        private val diskIO: Executor,
        private val networkIO: Executor,
        private val mainThread: Executor
    ) {
    What is going on here? https://github.com/googlesamples/android-architecture-components/blob/master/GithubBrowserSample/app/src/main/java/com/android/example/github/AppExecutors.kt#L35 https://kotlinlang.org/docs/reference/classes.html
    b
    • 2
    • 3
  • s

    Sudhir Singh Khanger

    07/19/2018, 3:27 AM
    If the class has a primary constructor, each secondary constructor needs to delegate to the primary constructor, either directly or indirectly through another secondary constructor(s). Delegation to another constructor of the same class is done using the this keyword:
    class Person(val name: String) {
        constructor(name: String, parent: Person) : this(name) {
            parent.children.add(this)
        }
    }
    Are there any examples of direct and indirect delegation here? What is
    parent.children.add(this)
    ?
    s
    • 2
    • 1
  • j

    Jogendra Shekhawat

    07/19/2018, 12:52 PM
    if (javaClass != other?.javaClass) return false is is equal to if (this.javaClass != other?.javaClass) return false
    s
    • 2
    • 6
  • b

    Benjamin Drucker

    07/19/2018, 11:51 PM
    I have tried ktlint to apply standard settings to Android Studio, but they also don’t work. The settings do not product kotlin code that can successfully pass ktlint checks
    s
    s
    • 3
    • 2
  • t

    Tom Adam

    07/20/2018, 7:51 AM
    Hei, I was wondering if there is a comprehensive list of valid strings to be used inside @Supress annotations?
    k
    • 2
    • 1
  • d

    diesieben07

    07/20/2018, 1:24 PM
    val instance by lazy { SomeClass() }
    s
    • 2
    • 3
  • m

    Michel

    07/20/2018, 1:27 PM
    For singleton, simply use Object declaration : https://kotlinlang.org/docs/reference/object-declarations.html#object-declarations
    d
    • 2
    • 1
  • k

    kango_v

    07/20/2018, 1:30 PM
    I'm just starting to play around and have this little test:
    class Test (
        val id: UUID
    ) {
    	private constructor(builder: Builder) : this(builder.id)
    	companion object {
    		inline fun build(id: UUID, block: Builder.() -> Unit)  = Builder(id). apply(block).build()
    	}
    	class Builder(
    		val id: UUID) {
            var text: String? = null
            fun build() = Test(this)
        }
    }
    but, at
    apply
    , i'm getting
    Unresolved reference: apply
    . I am using the Eclipse Kotlin plugin. I know, I should be using IDEA....... one step at a time. 🙂
    a
    k
    • 3
    • 6
  • o

    oday

    07/21/2018, 6:29 PM
    if yes, then that’s what it means, if no, then it means “some of these params will be injected”
    s
    k
    u
    • 4
    • 10
Powered by Linen
Title
o

oday

07/21/2018, 6:29 PM
if yes, then that’s what it means, if no, then it means “some of these params will be injected”
s

Shawn

07/21/2018, 6:30 PM
gonna detour into a thread since this isn’t exactly Kotlin related
k

karelpeeters

07/21/2018, 6:30 PM
Right, what library are you using?
o

oday

07/21/2018, 6:31 PM
just javax so far
i only use Dagger usually, it doesn’t work like this
I think that he is writing this and later he will write the file that dictates what can be injected and where
🙂
sorry wasted your time
u

ursus

07/22/2018, 3:26 PM
contructor injection is meat and potatoes of Dagger, field injection is only when you cant use ctor inj.
o

oday

07/23/2018, 8:49 AM
not sure about that
u

ursus

07/23/2018, 2:25 PM
if you believe in DI, you believe in passing all dependencies via constructor as the best case, if you dont, you dont
View count: 3