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

    Ruckus

    02/17/2017, 4:52 PM
    Thanks (I should have specified I meant the code in the
    coroutines-guide.md
    )
    e
    • 2
    • 2
  • k

    kirillrakhman

    02/20/2017, 4:09 PM
    A property containing it's own name:
    object Name {
        operator fun provideDelegate(thisRef: Any?, property: KProperty<*>) = property.name
    }
    
    operator fun String.getValue(thisRef: Any?, property: KProperty<*>) = this
    
    val foo by Name
    
    fun main(args: Array<String>) {
        println(foo) //prints "foo"
    }
    g
    • 2
    • 3
  • j

    jackmiras

    02/20/2017, 4:10 PM
    Hey guys, how can I call a function extension that is declared in another class?
    k
    a
    • 3
    • 17
  • d

    dhkim

    02/21/2017, 1:00 PM
    When deciding on which one of overloaded functions are invoked, why isn't nullability considered?
    fun func(a: Any?) {}
    
    fun <T> func(a: Collection<T>) {}
    
    fun main(args: Array<String>) {
    	func(null) // Type inference fails here
    }
    i
    • 2
    • 2
  • j

    jackmiras

    02/21/2017, 1:57 PM
    @Paul Woitaschek in a case like this:
    override fun post(req: Request, res: Response): Any {
            val platform = req.bodyAsObject() as Platform
            if (platform.isValid()) {
                PlatformRepository().save(platform)
                return object { val message = "Platform created" ; val status = 201 }
            } else {
                return renderInvalidParams()
            }
        }
    I could avoid doing the
    if else
    statement by using functions as callback... just like this:
    override fun post(req: Request, res: Response): Any {
            req.bodyAsObject(success = {
                PlatformRepository().save(platform)
                return object { val message = "Platform created" ; val status = 201 }
            }, failure = {
                return renderInvalidParams()
            })
        }
    m
    • 2
    • 6
  • x

    xolan

    02/21/2017, 1:58 PM
    apply plugin: 'kotlin'
    apply plugin: 'application'
    apply plugin: 'org.junit.platform.gradle.plugin'
    
    buildscript {
        ext.kotlin_version = '1.0.6'
    
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3'
        }
    }
    ---snip---
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/home/xolan/work/accounter/build.gradle' line: 1
    
    * What went wrong:
    A problem occurred evaluating root project 'accounter'.
    > Failed to apply plugin [id 'kotlin']
       > For input string: ""
    Any suggestions? Can't seem to figure this one out
    • 1
    • 1
  • j

    jackmiras

    02/21/2017, 1:59 PM
    @jjnguy My bad 😅
    j
    • 2
    • 2
  • d

    dhkim

    02/21/2017, 2:07 PM
    @mg6maciej Thanks for confirming it. I had reasons for overloading my function but will try the other route to workaround the problem.
    m
    • 2
    • 1
  • o

    orangy

    02/22/2017, 12:24 AM
    I think we mark params, no? Can't check now, but may be incompatible annotations?
    g
    • 2
    • 4
  • d

    dragas

    02/22/2017, 10:30 AM
    @Eugenio You could try changing language inspection settings. Also, why not use
    reminderSubscription?.unsubscribe()
    instead?
    e
    • 2
    • 2
  • r

    robin

    02/22/2017, 12:05 PM
    So you don't have a noop. This is basically the same as doing:
    val unwrapped = optional
    if(unwrapped != null) { doSmth() }
    else { doSmthElse() }
    m
    a
    • 3
    • 5
  • r

    robin

    02/22/2017, 12:32 PM
    Well, if your system architecture is that broken that you're getting unexpected side effects all over the place... Let me just say, the stricter type system is only going to help you there. As I said I don't know how it works in swift, but if you have a val that the compiler has inferred to not be null, that val will not be null, period. No way that could change.
    m
    • 2
    • 1
  • j

    johnl

    02/22/2017, 12:36 PM
    since they dont seem to be bulletproof in swift
    m
    • 2
    • 10
  • j

    johnl

    02/22/2017, 1:02 PM
    would Kotlin help me besides optionals and monkey patching utils
    r
    • 2
    • 22
  • s

    somoni

    02/22/2017, 2:57 PM
    then when i open a kotlin file in my project (i am using gralde btw) it forces me to put this in my gradle file which is still 1.0.6
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    }
    i
    • 2
    • 9
  • o

    orangy

    02/22/2017, 7:31 PM
    Isn’t it a memory leak with OOM?
    g
    • 2
    • 20
  • c

    ccrowe

    02/22/2017, 9:23 PM
    @jjnguy I get the NPE when the function is called. It never actually executes the code. The only way I found is to write implementation in java and use that.
    m
    • 2
    • 1
  • d

    dalexander

    02/22/2017, 9:49 PM
    @somoni You could use a when statement, I don’t know that it’s actually O(1) but it’s definitely no worse than an if/else chain. ie.
    val obj: Any = "asdf"
        when(obj) {
            is Int -> println("Int!")
            is Double -> println("Double!")
            is String -> { println("String!") } // you can add braces if you have a longer statement
        }
    g
    • 2
    • 1
  • g

    groostav

    02/23/2017, 10:57 AM
    does anybody know whats causing this? It happens when I try to build with intelliJ:
    Error: Kotlin: Multiple values are not allowed for plugin option org.jetbrains.kotlin.kapt:outputPlugin
    a
    • 2
    • 6
  • o

    orangy

    02/23/2017, 10:59 AM
    @groostav are you using an RC build?
    g
    • 2
    • 2
  • n

    nkiesel

    02/23/2017, 7:58 PM
    Lua has the nifty feature that
    map["hello"]
    can be written as
    map.hello
    (as long as the key is a valid identifier). That's Lua's way to compensate for not having classes with properties. The
    by map
    property delegate in Kotlin does something similar, but requires to explicitly list all the properties. Any chance that Kotlin would be able to do the same?
    👎 5
    v
    • 2
    • 1
  • g

    groostav

    02/23/2017, 11:47 PM
    yeah @nkiesel, I think the suspected use case for
    val x by map
    was that it would primarily operate on objects of disparate types (a le Javascript), thus I think the
    by map
    idea was largely aimed as a shim for dynamic languages into kotlin. But I could agree with your assestment, especially when we have access to raw types. Perhaps it would be better if we had something like
    val map: Map<String, Any?> = ...
    val name:String by map //compiler error: cannot use `Map<String, Any?> as delegate for `val name: String` expected Value type to be String but was Any?
    
    val name: String by (map as Map) //compiler warning: unchecked raw type cast: Map<String, Any?> to Map
    val name: String by @SuppressWarnings("unchecked")(map as Map) //compiles without issue
    unfortunately its a moot point since any change would break backwards compatibility in a pretty big way
    n
    • 2
    • 3
  • j

    jackmiras

    02/24/2017, 4:22 PM
    Hey guys, there is an alternative or a better solution than slf4j library?
    o
    a
    • 3
    • 4
  • c

    curioustechizen

    02/25/2017, 2:07 PM
    Any ideas?
    c
    g
    • 3
    • 9
  • s

    sreich

    02/25/2017, 5:25 PM
    What's the differences between me using lateinit var and by lazy, for stuff that gets init'd after create (), like Android, games etc
    b
    m
    • 3
    • 7
  • u

    uli

    02/26/2017, 11:08 AM
    Can someone point me to a design document or discussion, why kotlin decided against statics?
    a
    • 2
    • 3
  • s

    sreich

    02/26/2017, 12:55 PM
    i don't suppose there's a way to say
    when (foo) { != 0 -> stuff(); else -> blah() }
    , while still using the var specifier, aka the
    (foo)
    b
    a
    g
    • 4
    • 10
  • m

    mikehearn

    02/26/2017, 3:49 PM
    Has anyone seen a problem with 1.1RC whereby the stdlib isn't on the classpath when trying to start a simple spring boot app from the IDE? I get an error saying it can't find the kotlin.jvm.internal.Intrinsics class
    i
    • 2
    • 5
  • a

    adibfara

    02/27/2017, 7:45 AM
    Does Gson work well with Kotlin data classes?
    m
    r
    f
    • 4
    • 11
  • m

    miha-x64

    02/27/2017, 10:33 AM
    Why I can’t have
    inner object
    ?
    private inner object Thing : Something {
    looks logically similar to
    private val thing = object : Something {
    ...
    g
    • 2
    • 1
Powered by Linen
Title
m

miha-x64

02/27/2017, 10:33 AM
Why I can’t have
inner object
?
private inner object Thing : Something {
looks logically similar to
private val thing = object : Something {
...
g

groostav

02/27/2017, 10:51 AM
miha-x64: https://youtrack.jetbrains.com/issue/KT-13453
👍 1
View count: 2