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

    uli

    03/01/2017, 5:42 PM
    Is it known, that trykotlin does not show anything in the 'Genrated classfiles' tab? Works fine for 'generated JavaScript code'
    r
    • 2
    • 2
  • d

    dimsuz

    03/01/2017, 5:43 PM
    @semoro nope, I only tried to write one, then deleted that line...
    s
    • 2
    • 2
  • n

    nfrankel

    03/01/2017, 8:37 PM
    @orangy pro tip: don’t use gradle...
    👍 2
    ✅ 1
    👏 1
    👎 6
    j
    • 2
    • 2
  • n

    nkiesel

    03/01/2017, 10:57 PM
    1.1 allows
    _
    for unused parameters of lambda expressions (and it seems also for unused values in a destructive assignments). Why does that not also work for unused parameters of methods? e.g.
    fun main(_: Array<String>) {
    l
    o
    • 3
    • 4
  • c

    cypher121

    03/02/2017, 7:30 AM
    @nkiesel this is really only useful for
    main
    , since parameter names should match parent's when overriding so that named arguments work properly. idea even has a warning for that
    n
    • 2
    • 1
  • a

    aaverin

    03/02/2017, 7:43 AM
    Was anybody successful running spek + mokito2 + spring?
    m
    • 2
    • 3
  • y

    yole

    03/02/2017, 7:45 AM
    @nkiesel you shouldn't get any unused parameter warnings on either
    main
    or implemented interface methods, even if you don't rename them to
    _
    👍 1
    n
    • 2
    • 3
  • p

    permalmberg

    03/02/2017, 7:15 PM
    Hey guys. do you have any issues with intellij refusing to realise that it has configured projects for Kotlin? Mine simply refuses to close the "Kotlin not configured" "yellow bar" at the top of the editor even though I've run through the hoops and it says it has added Kotlin to the projects.
    p
    • 2
    • 2
  • o

    okkero

    03/02/2017, 9:52 PM
    is nested destructuring on the roadmap?
    v
    • 2
    • 7
  • g

    gerson

    03/03/2017, 3:12 PM
    Hi guys. Is there an easy way to exclude a property from being used in generated toString() in data class (without implementing my own toString())?
    m
    r
    • 3
    • 10
  • v

    voddan

    03/04/2017, 8:09 PM
    Whom from JetBrains may I ask about the DSL marker design?
    i
    • 2
    • 3
  • r

    ribesg

    03/05/2017, 9:29 AM
    @mg6maciej Here's what I did, in Kotlin 1.1:
    fun <T> List<T>.batched(batchSize: Int): List<List<T>> {
        check(batchSize > 0) { "Invalid value for parameter 'batchSize': $batchSize (should be greater than 0)" }
        val batchAmount = (size + batchSize - 1) / batchSize
        val result = List<MutableList<T>>(batchAmount) { ArrayList(batchSize) }
        var index = 0
        forEach { result[index++ / batchSize].add(it) }
        return result
    }
    You seem to care about optimization, so note than when called on a
    LinkedList
    , your implementation does a O(N)
    get
    call on line 13
    👍 1
    m
    g
    • 3
    • 4
  • y

    yole

    03/05/2017, 5:15 PM
    @svenjacobs looks like https://youtrack.jetbrains.com/issue/KT-16184
    s
    • 2
    • 1
  • j

    jasoet

    03/06/2017, 2:59 AM
    is this intentional?
    n
    j
    • 3
    • 4
  • g

    groostav

    03/06/2017, 6:28 AM
    is it intended behavior that
    fun ParseNode.accept(visitor: Visitor){
        when(this){
            is NodeTypeA -> this.internalAccept(visitor::visitEnter, visitor::visitLeave)
        }
    }
    
    private fun <T> T.internalAccept(enter: (T) -> Unit, leave: (T) -> Unit): Unit = TODO()
    will not compile without the
    this.
    infront of
    internalAccept
    ? It seems like theres a corner case I'm hitting between smart casting and type inference that isnt covered here.
    a
    • 2
    • 2
  • s

    seanf

    03/06/2017, 6:57 AM
    @smcvb We've hit this too. It sounds like https://youtrack.jetbrains.com/issue/KT-15778
    s
    • 2
    • 2
  • d

    dimsuz

    03/06/2017, 12:11 PM
    kotlin 1.1 gradle incremental compilation is broken for me, it recompiles every time. What can I do to create a useful bug report if I can't share the project (closed source)? Maybe some compiler switch to produce additional logs?
    h
    • 2
    • 4
  • p

    ptashcka

    03/06/2017, 1:09 PM
    hey! after plugin upgrade to 1.1 version can't make a project in IDEA with the following error: Error:Kotlin: [Internal Error] org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong code generated org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node: next ()Lkotlin/Pair;: has anyone seen it? any workaround? maybe there is a way to downgrade the plugin in IDEA?
    m
    • 2
    • 13
  • d

    dstarcev

    03/06/2017, 4:00 PM
    How do I create a map with case-insensitive string keys? Currently do so
    mapOf(…).toSortedMap(CASE_INSENSITIVE_ORDER)
    i
    • 2
    • 1
  • r

    robin

    03/06/2017, 8:03 PM
    Is there any way to construct an instance that will equal any other object? This comes close:
    val any = object {
        override fun equals(other: Any?) = true
    }
    but only works when doing
    any == "Test"
    , not the other way around:
    "Test" == any
    . Is there any way to make the latter work?
    m
    • 2
    • 8
  • e

    eygraber

    03/06/2017, 9:49 PM
    Does it make sense that calling the following extension function on a null
    String?
    would print
    int?
    inline val <reified T : Any?> T.TAG get() = ((this as? Any)?.javaClass?.simpleName ?: "${T::class.java.simpleName ?: "null"}?").replace("CompanionObject", "")
    m
    • 2
    • 7
  • j

    jlleitschuh

    03/06/2017, 10:56 PM
    does
    toMutableList
    on a mutable list copy that list? Otherwise, how do you copy a list? I could use the
    ArrayList
    constructor but if there is a kotlin way of copying a list I'd rather do that.
    m
    • 2
    • 3
  • a

    andrewoma

    03/07/2017, 3:59 AM
    @groostav It seems an odd thing to do to me, but here’s a way:
    fun <T> split(values: List<T>, vararg lengths: Int): Sequence<List<T>> {
        val lengthsSeq = lengths.iterator()
        val valuesSeq = values.iterator()
        return generateSequence { if (lengthsSeq.hasNext()) List<T>(lengthsSeq.next()) { valuesSeq.next() } else null }
    }
    
    val result = split(listOf("one", "two", "three", "four", "five", "six", "seven", "eight"), 3, 2, 3).associateBy { it.first() }
    
    assertEquals(result, mapOf(
            "one" to listOf("one", "two", "three"),  //row length == 3
            "four" to listOf("four", "five"),        //len == 2
            "six" to listOf("six", "seven", "eight") //len == 3
    ))
    ➕ 1
    g
    • 2
    • 2
  • m

    mg6maciej

    03/08/2017, 8:18 AM
    With type aliases in place you cannot go to declaration (
    cmd+B
    ,
    cmd+click
    ) or see args of constructor (
    cmd+P
    inside brackets; tooltip is micro and empty), e.g.
    public typealias ArrayList<E> = java.util.ArrayList<E>
    s
    • 2
    • 7
  • m

    mikehearn

    03/08/2017, 9:20 AM
    gradle will automatically bump up the stdlib to 1.1 if necessary to keep things consistent
    👍 2
    m
    n
    • 3
    • 21
  • d

    doubleu

    03/08/2017, 11:01 AM
    Hello, I was gonna ask a question about delegation here but since it became too long i moved it to StackOverflow instead. If I may be so bold I will still link it there tho 😈 http://stackoverflow.com/questions/42669433/kotlin-how-are-a-delegates-get-and-setvalue-methods-accessed
    r
    • 2
    • 3
  • g

    grahamborland

    03/08/2017, 11:17 AM
    Is this still the nicest (or only) syntax for multiple annotations on a field?
    @field:[Inject Named("ActiveBudgetId")] internal lateinit var activeBudgetId: String
    Not quite as nice as the Java equivalent
    @Inject @Named("ActiveBudgetId") String activeBudgetId;
    o
    • 2
    • 4
  • s

    sannysanoff

    03/08/2017, 12:36 PM
    Hello, please advise where to start (what web framework) if I want to use asynchronous web server with asynchronous postgres driver (found port from scala). Coming from Scala, new in Kotlin, now in process of selecting the platform. Thanks in advance!
    v
    j
    • 3
    • 6
  • v

    voddan

    03/08/2017, 12:39 PM
    How do I overpower a Java
    div
    method??? http://stackoverflow.com/q/42666760/3144601
    a
    • 2
    • 1
  • s

    spand

    03/08/2017, 3:33 PM
    Ie. something like
    String.{ trim() }
    so it would have the type
    String.() -> String
    r
    l
    m
    • 4
    • 12
Powered by Linen
Title
s

spand

03/08/2017, 3:33 PM
Ie. something like
String.{ trim() }
so it would have the type
String.() -> String
r

robin

03/08/2017, 3:35 PM
val test: String.() -> Unit = { trim() }
And if you're not using the lambda in an assignment it's probably in a function call, where type inference should make the explicit declaration unnecessary.
s

spand

03/08/2017, 3:39 PM
My usecase is something like this
val foo : String.() -> Unit = when(false){
                        true -> {}
                        false -> {}
                    }
and it fails to infer
l

lupajz

03/08/2017, 3:51 PM
You are not returning your function there
val foo : String.() -> Unit = when(false){
    true -> { {} }
    false -> { {} }
}
👍 1
m

mfulton26

03/08/2017, 3:56 PM
You can use anonymous function: https://kotlinlang.org/docs/reference/lambdas.html#anonymous-functions
val foo = when (false) {
    true -> fun String.() {}
    false -> fun String.() {}
}
r

robin

03/08/2017, 4:11 PM
@lupajz Is right, in your example the braces are treated as block delimiters for the when-branch, not as lambdas.
l

lupajz

03/08/2017, 4:14 PM
It would be really cool if this worked sometime in future. I would love not have to write 2 sets of braces 😕
r

robin

03/08/2017, 4:21 PM
@lupajz You could do it this way:
val foo : String.() -> Unit = when(false){
    true -> { -> }
    false -> { -> }
}
Same amount of characters to type, but at least it's a bit easier to read imo.
👍🏻 1
l

lupajz

03/08/2017, 4:27 PM
@robin that’s nice! never used that thanks
r

robin

03/08/2017, 4:28 PM
Me neither, but your comment made me wonder whether the arrow notation works even with no parameters, turns out it does 😄
s

spand

03/09/2017, 7:27 AM
Lovely. Thanks for the replies !
View count: 3