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

    phldavies

    12/14/2018, 12:06 PM
    Given a java class with a setter taking a non-nullable value, and kotlin extension function with a nullable parameter, what's idiomatic way to call the setter if the param is non-null?
    fun MyPojo.init(fieldName: String? = null) {
                fieldName?.let(::setFieldName)
                fieldName?.also { setFieldName(it) }
                fieldName?.also { this.fieldName = it }
                if(fieldName != null) setFieldName(fieldName)
                if(fieldName != null) this.fieldName = fieldName
    }
    s
    c
    • 3
    • 4
  • d

    dmcg

    12/14/2018, 1:37 PM
    Anyone got a good way of making a parent-child relationship without mutating one or the other? https://stackoverflow.com/questions/53130288/how-do-i-create-a-parent-child-relationship-in-immutable-kotlin-classes
    d
    p
    • 3
    • 4
  • x

    xenoterracide

    12/14/2018, 6:54 PM
    dependencies {
        compile(kotlin("stdlib", "1.3.11"))
    }
    w: Runtime JAR files in the classpath have the version 1.2, which is older than the API version 1.3. Consider using the runtime of version 1.3, or pass '-api-version 1.2' explicitly to restrict the available APIs to the runtime of version 1.2. You can also pass '-language-version 1.2' instead, which will restrict not only the APIs to the specified version, but also the language features
    w: /tmp/.gradle-test-kit-xeno/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.71/ba18ca1aa0e40eb6f1865b324af2f4cbb691c1ec/kotlin-stdlib-common-1.2.71.jar: Runtime JAR file has version 1.2 which is older than required for API version 1.3
    w: /tmp/.gradle-test-kit-xeno/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar: Runtime JAR file has version 1.2 which is older than required for API version 1.3
    e: /tmp/junit14078856699846774951/junit17290987759747338376/src/main/kotlin/com/xenoterracide/test/Test.kts: (17, 1): Cannot access script base class 'kotlin.script.templates.standard.ScriptTemplateWithArgs'. Check your module classpath for missing or conflicting dependencies
    how do I make kotlin 1.3 work? or heck, even 1.2… no matter what I seem to do it seems to end up with this error
    g
    • 2
    • 5
  • d

    Dico

    12/14/2018, 8:15 PM
    Are the messages from @xenoterracide And @blogscot related?
    b
    • 2
    • 2
  • t

    tschuchort

    12/14/2018, 10:59 PM
    Is there any way to pass
    this
    to a mixin class that implements an interface via delegation? (i.e.
    class Class : Interface by Mixin(this)
    . It's possible to pass
    this
    but for some reason it refers to the companion instead of the instance itself. I realize that I could just instantiate the mixin in the class body and delegate all methods manually, but that's quite annoying.
    c
    • 2
    • 4
  • d

    Dalinar

    12/15/2018, 8:22 AM
    I'm using a java library called Caffeine which is actually fairly similar to Guava Caches in syntax. However, I've run into this problem (I'm extremely rusty on Kotlin since I haven't touched it in a year).. so.. how do I solve this? (make it nicer)
    `
    private val requests: Cache<String, Req> = Caffeine.newBuilder()
                .removalListener<String, Req> { clientOrderID: String?, req: Req?, removalCause: RemovalCause ->
                    clientOrderID!!; req!!
                    ...
                    req.close()
                }
    `
    with Guava the code would compile without the `?
    on the parameters
    
    the reason I added these
    !!
    where I did was because I refer to these variables several times in the code afterwards. However what I'm asking is if there is a nicer syntax where I can somehow get rid of the
    ?` on the parameters very strange, my other similar caches built in the same way have no problem accepting non-nullable parameters in
    removalListener
    - it's just this particular one that is the problem
    k
    • 2
    • 10
  • x

    xenoterracide

    12/15/2018, 8:44 AM
    does kotlin have a BOM for its "core" libraries?
    i
    • 2
    • 1
  • x

    xenoterracide

    12/15/2018, 6:05 PM
    the getter is required by Persistable
    k
    • 2
    • 7
  • x

    xenoterracide

    12/15/2018, 6:06 PM
    are there any issues to vote for regarding private/protected vals on interfaces?
    a
    • 2
    • 1
  • s

    simon.vergauwen

    12/16/2018, 12:26 PM
    Any1 has experience with CircleCI? My builds keep failing with exitcode 127. According to CircleCI docs that means that my mem consumption is too high and they’re killing the gradlew child process.
    c
    t
    • 3
    • 5
  • d

    Dominaezzz

    12/16/2018, 4:30 PM
    If a member function only uses public members of it's class, should it be converted to an extension function? :yes:/🇳🇴
    a
    k
    r
    • 4
    • 23
  • i

    itnoles

    12/16/2018, 6:19 PM
    Travis CI has flaky network connections
    j
    • 2
    • 1
  • a

    aris

    12/16/2018, 7:50 PM
    i have a error because after $ i have a qh41, and kotlin think is a variable
    j
    • 2
    • 6
  • p

    Paul Woitaschek

    12/16/2018, 9:21 PM
    It's my own project, the modules are my modules, what's impossible here for a smartcast?
    r
    • 2
    • 3
  • g

    groostav

    12/17/2018, 1:52 AM
    can somebody tell me why this is legal kotlin?
    -.groovy
    :youtrack: 1
    🐞 1
    k
    d
    • 3
    • 5
  • c

    Czar

    12/17/2018, 1:12 PM
    Are we stuck with the following situation? java declaration
    public abstract <R> java.util.concurrent.CompletableFuture<R> send(Object command)
    Java call
    object.send(command);
    nice 👍 :java: Kotlin call
    object.send<Any>(command)
    not nice, I'd like to avoid having to write
    <Any>
    👎 :kotlin:
    a
    s
    g
    • 4
    • 7
  • p

    Paul Woitaschek

    12/17/2018, 1:52 PM
    I like it because for me a class like this is actually rather a function than a class with actual methods. So this ready naturally.
    n
    a
    • 3
    • 5
  • s

    Slackbot

    12/17/2018, 8:08 PM
    This message was deleted.
    a
    r
    • 3
    • 4
  • s

    serebit

    12/18/2018, 12:15 AM
    So when are we getting kotlin.color/kotlinx.color?
    ❓ 9
    s
    e
    • 3
    • 3
  • a

    Amir

    12/18/2018, 8:35 AM
    Hey guys, I'm new to programing and I decided to learn Kotlin and I'm more interested in Kotlin for Android. Is there any website with tutorials for complete beginners? Also, is it better to first start with learning Kotlin itself and then learn kotlin for Android, or I can learn from very beginning the kotlin for Android.
    t
    • 2
    • 3
  • k

    karelpeeters

    12/18/2018, 8:41 AM
    Do you already know Java? If so, I'd recommend going trough the reference starting here: https://kotlinlang.org/docs/reference/basic-syntax.html and after that start Android.
    a
    • 2
    • 1
  • r

    rrader

    12/18/2018, 10:52 AM
    What library do you use for SQL/Database?
    a
    g
    +2
    • 5
    • 8
  • m

    mikehearn

    12/18/2018, 2:35 PM
    We're going to write a tool to provide ABI stability when new parameters with default values are added, to unblock our release, but it'd be good to know what this param is for - if anything.
    i
    m
    • 3
    • 4
  • g

    grahamborland

    12/18/2018, 3:34 PM
    Why does this compile?
    private fun shouldNotCompile(optionalString: String?): Boolean {
            optionalString?.let {
                return true
            }
        }
    I’ve completely forgotten to specify a return value for the case where the
    let
    is not entered.
    🐛 1
    e
    a
    i
    • 4
    • 4
  • g

    grahamborland

    12/18/2018, 3:40 PM
    Thanks, will report
    p
    • 2
    • 4
  • c

    cristiangm

    12/18/2018, 5:12 PM
    Kotlin compiler prints warnings but, it would be wonderful if we could have them on a XML report
    m
    • 2
    • 7
  • s

    SrSouza

    12/18/2018, 6:20 PM
    Have one more question, everytime a create and use a function with contract I need to add the annotation
    @ExperimentalContracts
    ?
    i
    e
    • 3
    • 3
  • r

    Rohan Maity

    12/18/2018, 10:52 PM
    @elizarov is there any chance that jetBrains come for GSOC'19 for Kotlin Lang ?
    e
    • 2
    • 5
  • t

    tipsy

    12/19/2018, 9:29 AM
    i'm trying to call a jdbi-method from kotlin, and i get:
    Type inference failed: Not enough information to infer parameter X in 
    fun <R : Any!, X : Exception!> withHandle(callback: ((handle: Handle!) → R!)!): R!
    Please specify it explicitly.
    the method signature is
    public <R, X extends Exception> R withHandle(HandleCallback<R, X> callback) throws X {
    what am i supposed to do in this case?
    g
    • 2
    • 5
  • r

    rrader

    12/19/2018, 10:23 AM
    What Kotlin feature is used for
    object Users : Table() {
        val id = varchar("id", 10).primaryKey() // Column<String>
        val name = varchar("name", length = 50) // Column<String>
        val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
    }
    Users.insert {
                it[id] = "andrey"
                it[name] = "Andrey"
                it[cityId] = saintPetersburgId
            }
    how compiler know that
    it[id]
    is valid and for example
    it[title]
    is not valid? from https://github.com/JetBrains/Exposed
    r
    m
    • 3
    • 9
Powered by Linen
Title
r

rrader

12/19/2018, 10:23 AM
What Kotlin feature is used for
object Users : Table() {
    val id = varchar("id", 10).primaryKey() // Column<String>
    val name = varchar("name", length = 50) // Column<String>
    val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
}
Users.insert {
            it[id] = "andrey"
            it[name] = "Andrey"
            it[cityId] = saintPetersburgId
        }
how compiler know that
it[id]
is valid and for example
it[title]
is not valid? from https://github.com/JetBrains/Exposed
r

reik.schatz

12/19/2018, 11:00 AM
maybe ask in #exposed but it looks like
.insert
is an extension function and then
id
,
name
and
cityId
are just
Column
instances given to the
InsertStatement
and
val title: Column<?>
just doesn’t exists in your
Users
object
r

rrader

12/19/2018, 11:03 AM
but how it knows that columns are from
Users
and not from other
object
?
r

reik.schatz

12/19/2018, 11:06 AM
because
.insert
is added to
Users
fun <T:Table> T.insert(body: T.(InsertStatement<Number>)->Unit): InsertStatement<Number> = InsertStatement<Number>(this).apply {
    body(this)
    execute(TransactionManager.current())
}
T
is a specific type
again, I am new to Kotlin. ask in #exposed 🙂
r

rrader

12/19/2018, 11:45 AM
ok, thanks
m

Mike

12/19/2018, 1:48 PM
@rrader
insert
is an extension function on all types.
body
is a Lambda with receiver. Some more advanced Kotlin features that allow for powerful DSL’s. Hopefully those keywords give you some direction for research. But ultimately, the Lambda you’re passing to
insert
(everything inside the {}) has a single parameter
it
that is of the type of the class
insert
is being called on. So in this case, the compiler knows that
it
is of type
Users
View count: 2