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
getting-started
  • m

    miha-x64

    04/17/2017, 1:28 PM
    @annyce typically, we use Egyptian curly braces, like in Java, not in C. A question to developers of Kotlin. Should constants be
    const val
    or not?
    s
    a
    • 3
    • 7
  • m

    miha-x64

    04/17/2017, 7:12 PM
    Was
    for (x in a until b)
    ever optimized by compiler?
    i
    s
    • 3
    • 3
  • s

    s.luhmirins

    04/18/2017, 9:43 AM
    constructors must be as quick and simple as possible
    s
    • 2
    • 3
  • m

    miha-x64

    04/18/2017, 6:16 PM
    No, there will be an unsuccessful cast.
    a
    k
    g
    • 4
    • 4
  • e

    evkaky

    04/19/2017, 1:51 PM
    Hi guys. Does anybody know, kotlin compiler uses ANTLR under the hood? Or jetbrains wrote compiler from the ground up?
    e
    • 2
    • 1
  • t

    teedee

    04/19/2017, 2:16 PM
    Is there a way to expose a property as List outside of the class but access it as MutableList inside the class?
    m
    • 2
    • 2
  • g

    germangb

    04/19/2017, 8:26 PM
    Is there a reason why kotlin doesn't have "regular looking" bitwise operators? (&, |, ~, >>, <<), I find it pretty annoying...
    e
    e
    d
    • 4
    • 3
  • r

    roberto.guerra

    04/20/2017, 4:56 PM
    is there a specific Kotlin library people are using for parsing XML ?
    v
    • 2
    • 2
  • b

    beholder

    04/20/2017, 10:23 PM
    Why "don't work"? I have
    @XStreamAlias
    annotations attached to Kotlin data classes
    a
    • 2
    • 1
  • c

    codematix

    04/21/2017, 8:47 AM
    do I need my class to implement or extend some specific interface or class to support destructuring?
    v
    o
    • 3
    • 7
  • p

    poohbar

    04/23/2017, 12:48 PM
    what am I doing wrong here guys?
    class Test() {
        var l: List<Int> = mutableListOf()
    
        init {
            l.add(4) // Unresolved
        }
    }
    a
    c
    • 3
    • 4
  • m

    miha-x64

    04/24/2017, 10:49 AM
    Any way to write this in funcitonal fashion?
    controls.mapValues {
        val ans = EnumSet.noneOf(NotificationTarget::class.java)
        if (it.value.pushSwitch.isChecked) ans += NotificationTarget.PUSH
        if (it.value.emailSwitch.isChecked) ans += NotificationTarget.EMAIL
        ans
    }
    o
    • 2
    • 7
  • m

    miha-x64

    04/24/2017, 4:03 PM
    Is there any less-allocative way to do this? Make User mutable?
    var user = state.user
    sendToBackend(diff.mapValues { when (it.key) {
        "name" -> (it.value as String).also { user = user.copy(name = it) }
        "sex" -> ((it.value as Sex).also { user = user.copy(sex = it) }).name
        "birth" -> ((it.value as Calendar).also { user = user.copy(birth = it.time) }.timeInMillis / 1000L).toString()
        else -> throw AssertionError()
    } })
    😨 1
    s
    • 2
    • 1
  • a

    ahdezma

    04/25/2017, 1:20 PM
    Something like this?
    val errors = torrent.error?.let { listOf(it) }
    i
    • 2
    • 1
  • e

    elect

    04/26/2017, 5:19 PM
    what could an error such as
    java.lang.AbstractMethodError
    indicate?
    m
    • 2
    • 1
  • c

    chuck

    04/26/2017, 6:23 PM
    Is it possible to call inline kotlin functions from java code?
    :stackoverflow: 5
    k
    • 2
    • 1
  • r

    Ruckus

    04/27/2017, 3:36 AM
    @robsonj Generic types are erased at runtime, so both are actually just
    Remove(List)
    . You could resolve it by giving them separate JVM names, but for more clarification on that, you should check SO. 😒tackoverflow:
    👍 1
    r
    • 2
    • 1
  • d

    dcsg

    04/27/2017, 2:29 PM
    thanks in advance
    d
    • 2
    • 2
  • f

    firezenk

    04/28/2017, 2:17 PM
    Hi I’ve a vararg of
    Car
    and I’ve to pass it to a function that accepts vararg but it says the time that needs si `Nothing!`… but in Java is getting the correct type, any suggestions?
    u
    • 2
    • 2
  • b

    brianwernick

    04/28/2017, 2:46 PM
    In the meantime you can swap out the interface with a lambda reference (i.e.
    public void callingMethod(TestInterface interface)
    to
    fun callingMethod(lambda: (string) -> String)
    👍 1
    r
    n
    • 3
    • 8
  • k

    kojdecki

    04/28/2017, 2:56 PM
    @north don’t really know if it’s ok, but this works:
    interface TestInterface {
        fun apply(str: String): String
    }
    
    fun TestInterface(lambda: (String) -> String): TestInterface {
        return object : TestInterface {
            override fun apply(str: String): String = lambda(str)
        }
    }
    
    fun main(args: Array<String>) {
        var test = TestInterface { str: String -> str.apply { println(str) } }
        test.apply("test")
    }
    You can throw some inlines in there.
    n
    • 2
    • 1
  • d

    danneu

    04/28/2017, 7:05 PM
    a while back i wrote a library to learn kotlin. when i try to use it in another project, it throws
    java.lang.NoClassDefFoundError: com/beust/klaxon/Parser
    on this line: https://github.com/danneu/reddit/blob/master/src/main/kotlin/com/danneu/reddit/extensions.kt#L44 i'm not very experienced in java/kotlin, any pointers on what might cause this when using a library from another project?
    i
    • 2
    • 8
  • g

    gauravm8

    04/29/2017, 5:31 PM
    Hi....how to create below equivalent in kotlin public final class Constants { public static final String TWO_PANE_KEY = "is_two_pane"; private Constants() { } public static class DetailActivityKeys { public static final String STORY_URL_KEY = "storyURL"; public static final String IMAGE_URL_KEY = "imageURL"; public static final String SUMMARY_KEY = "summary"; public static final String TITLE_KEY = "title"; } public static class API { public static final String BASE_URL = "https://api.myjson.com/"; } } I know I can make on companion class to hold all constants .....but how to group constants in inner classes
    a
    a
    i
    • 4
    • 7
  • a

    arve

    04/29/2017, 5:34 PM
    Hi. I have a data class with three properties:
    MyClass(groupId, datetime, someValue)
    Next, I have a
    Set<MyClass>
    , which can contain multiple entries with the same groupId. I want to turn this into a
    Set<MyClass>
    that contains the latest(by datetime) entry for each groupId. What’s a good functional/stream-like way of achieving this?
    a
    • 2
    • 1
  • p

    pserzh

    04/29/2017, 8:09 PM
    Hi. Can someone tell me how to get a reference to the class container from the companion object? https://www.screencast.com/t/Txhuy9WiQ
    m
    • 2
    • 2
  • t

    tylerwilson

    05/02/2017, 2:15 AM
    Simple question about Kotlin JS: I am in a project folder with a local node_modules directory. I want to create a script.kt that does an import of a module within the node_modules. I am using the command-line compiler kotlinc-js, but nothing is found. What is the magic to allow the compiler to pull in JS from the node_modules? Do I have to run the ts2kt converter? Do I need a package.json of some sort? Thank you!
    b
    • 2
    • 3
  • m

    Moe

    05/02/2017, 1:10 PM
    I guess I puted my question the wrong way lets say I have class that have some fields and methods and inside it I have a companion object that need to access the fields and methods of the outer class
    w
    • 2
    • 13
  • e

    elect

    05/02/2017, 4:58 PM
    no way to `return`/`break` the
    init{ }
    ?
    s
    • 2
    • 2
  • e

    elizarov

    05/04/2017, 7:09 AM
    There is also
    Character.digit(ch: Char, radix: Int)
    , so you can simply do it straight away with:
    fun String.calc() = map { Character.digit(it, 10) }.reduce(Int::times)
    r
    • 2
    • 2
  • c

    cedric

    05/04/2017, 6:50 PM
    Anyone who’s dealt with Spring logging hundreds of lines of runtime exceptions can see what happens when you go full runtime
    r
    • 2
    • 5
Powered by Linen
Title
c

cedric

05/04/2017, 6:50 PM
Anyone who’s dealt with Spring logging hundreds of lines of runtime exceptions can see what happens when you go full runtime
r

Ruckus

05/04/2017, 7:07 PM
cedric: I'm curious on your perspective of how exceptions in Java are structured (hierarchically). I heard an argument once that having runtime exceptions extend from checked exceptions was the source of a lot of people's issues with exceptions in Java, and would have been better if runtime exceptions had their own hierarchy (extending directly from
Throwable
).
c

cedric

05/04/2017, 8:07 PM
@boom I don’t have a problem with the hierarchy, the key advantage of exceptions is in 1) compiler verified error handling and 2) automatic bubbling
r

Ruckus

05/04/2017, 8:09 PM
I agree with you on exceptions vs some sort of result type. I was just curious if you had any thoughts about Java's exception hierarchy specifically.
c

cedric

05/04/2017, 8:12 PM
I’ve never had an issue with exceptions that was caused by their hierarchy
r

Ruckus

05/04/2017, 8:26 PM
Fair enough. Thanks
View count: 2