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

    clubfan

    11/05/2017, 9:37 PM
    Yeah, that's how I got it 🙂
    k
    • 2
    • 4
  • n

    nucc

    11/05/2017, 9:40 PM
    hi, is there any way to initialize a immutable property in a data class in the constructor? In non-data class I've seen examples for the
    lazy
    keyword that might can help for me, but I don't know how I could use it in a data class. I want something like in C++ how we define a
    const
    instance variable in the constructor. Here is an example what I would like to do:
    data class MyClass(val property: String) {   # <-- mutable
    	init {
    		this.property = property.capitalize()
    	}
    }
    
    instance = MyClass("test")
    instance.property # Test
    instance.property = "test2" # error, immutable variable
    but unfortunately the compiler says
    Val cannot be reassigned
    when I set
    this.property
    . Do you know how I could use immutable instance variable here?
    k
    a
    e
    • 4
    • 22
  • j

    jen20

    11/05/2017, 10:20 PM
    Is there a canonical library to use for XML parsing in Kotlin?
    r
    • 2
    • 1
  • k

    kristofdho

    11/06/2017, 2:44 AM
    it would be a fancy feature though, default types
    a
    • 2
    • 1
  • d

    dasz

    11/06/2017, 9:26 AM
    Does anyone know why this is still an issue in Kotlin latest version? https://youtrack.jetbrains.com/issue/KT-3212
    o
    • 2
    • 5
  • k

    katz

    11/06/2017, 1:01 PM
    sadly - no. idea i need it to generate bytecode for
    object : TypeOf<ArrayList<CityInfo>>() {}
    class to allow gson to deserialize, so it means i need declare class exactly, any templates return type as T (not as ArrayList<CityInfo>)
    a
    • 2
    • 1
  • m

    mike_shysh

    11/06/2017, 1:57 PM
    Is anyone could help with this: How to write an extensions function if data class is defined in .kt file, not in kotlin separate class
    fun CustomerInfo.addRandomPartToName(): CustomerInfo {
        val oldItem = this.customerInfo <<<< `this` is not usable
        val newItem = oldItem?.copy(name = oldItem.name + RandomStringUtils.randomAlphabetic(7))
        return this.copy(customerInfo = newItem)
    }
    m
    • 2
    • 13
  • l

    louiscad

    11/06/2017, 2:08 PM
    Hi, does anyone knows how to count
    object
    ,
    enum
    and other Kotlin keywords if possible in a project? I'm looking for an OS agnostic way to count them if possible as I work on macOS and Windows 10
    d
    • 2
    • 2
  • t

    thos

    11/06/2017, 2:39 PM
    anyone use spring-data ( specifications ), please share your best practice for me ?
    n
    • 2
    • 1
  • h

    hagabaka

    11/06/2017, 5:44 PM
    is it possible to have a default value of type parameters in generics?
    k
    • 2
    • 2
  • k

    kristofdho

    11/06/2017, 6:29 PM
    untested and i'm not familiar with Kovenant either, but this should probably work
    fun <T> Deferred<Unit,T>.resolve() = resolve(Unit)
    h
    • 2
    • 7
  • k

    kartikpatodi

    11/06/2017, 8:22 PM
    @orangy @ilya.gorbunov Can tell why this example provided in the docs throwing exception on try.kotlinlang.org but works fine in the IDE
    inline fun <reified T> membersOf() = T::class.members
    
    fun main(s: Array<String>) {
        println(membersOf<StringBuilder>().joinToString("\n"))
    }
    https://try.kotlinlang.org/#/UserProjects/e8imtmr1ecig3054eh01oekq8q/s05q8o8o76i5jkum3ov36o3gpc
    o
    • 2
    • 4
  • k

    kovrik

    11/07/2017, 4:31 AM
    Hi! kotlin.sequences package has a flatten method (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/flatten.html). But it works only on a sequence of sequences (Sequence<Sequence<T>>). Are there any alternatives that will work on any sequence (Sequence<T>)? Something that behaves more like a flatten function in Clojure.
    o
    • 2
    • 10
  • h

    Hawk

    11/07/2017, 4:32 AM
    I'm getting some pretty poor behavior out of IntelliJ these days, I'm using a lot of fringe stuff so I'm assuming it's just a bunch of bugs around the edges. What's the best way to go about reporting them? Just post to your youtrack?
    o
    • 2
    • 7
  • a

    andyr

    11/07/2017, 9:12 AM
    just wondering is there a similar chat channel for Java ?
    k
    • 2
    • 1
  • p

    patrickdelconte

    11/07/2017, 9:29 AM
    Are the talks from kotlinconf already available online?
    k
    • 2
    • 1
  • a

    arthur

    11/07/2017, 11:28 AM
    Welcome onboard @Hunter. Does Honeypot use Kotlin?
    h
    • 2
    • 8
  • c

    christophsturm

    11/07/2017, 1:49 PM
    why is “this cast can never succeed” a warning and not an error?
    o
    n
    • 3
    • 5
  • s

    Slackbot

    11/07/2017, 4:44 PM
    This message was deleted.
    o
    • 2
    • 1
  • k

    Kartik Shandilya

    11/07/2017, 5:38 PM
    Hey guys I'm pretty new to Kotlin. Can anyone guide me some tutorials on Kotlin with Android.
    k
    • 2
    • 3
  • c

    cdurham

    11/07/2017, 6:52 PM
    does
    @Throws
    serve a purpose other than java interop?
    p
    t
    • 3
    • 8
  • k

    kevinmost

    11/07/2017, 7:52 PM
    I think that can just be
    return lines.joinToString(separator = if (newLine) separator else "")
    a
    • 2
    • 1
  • t

    tiare.balbi

    11/08/2017, 7:05 AM
    FYI: http://mockk.io/
    👍 10
    :kotlin: 4
    d
    m
    o
    • 4
    • 4
  • h

    helpermethod

    11/08/2017, 12:42 PM
    Hi, do you accept contributions? Would love to add some samples regarding the use of the JavaExec plugin and defining additional Source Sets
    k
    • 2
    • 1
  • o

    oleksiyp

    11/08/2017, 2:37 PM
    btw I think #kotlin should have very strong focus on testing tools, so that it's easy for Java dev to try it and benefit from having DSLs for testing. So it should be really Kotlin frameworks, no such stuff like "final" issue(kotlin really can allow to run tests with special option, not plugin), e.t.c. up to the approach when you counting clicks till writing first tests for existing Java/Maven/gradle project
    d
    e
    n
    • 4
    • 7
  • k

    kevinmost

    11/08/2017, 8:22 PM
    if you provide a body for an
    abstract
    member, that's used as the default if an implementation doesn't override it
    r
    • 2
    • 2
  • r

    radityagumay

    11/09/2017, 2:13 AM
    Hi, is anyone facing this problem.
    break or continue jump across class boundary kotlin
    this problem appears when i am going to use break or continue. inside lamda with receiver i create ‘letIn’
    lamda with receiver code
    fun letIn(componentName: String?, values: List<LifeService.Value?>?,
              body: (String, List<LifeService.Value?>) -> Unit) {
        if (!TextUtils.isEmpty(componentName) && (values != null && values.isNotEmpty())) {
            body(componentName!!, values)
        }
    }
    this sample code for it.
    for (option in 0 until optionsSize) {
    val component = optionsGroup?.options?.get(option)
            component?.let {
                with(component) {
                    letIn(presentation, values, { componentName, values ->
                        if (componentName == LifeComponentViewType.CHECKBOX) {
                            letIn(transformCheckBoxValues(optionsGroup), { data ->
                                dataSource?.push(componentName, ComponentDataCheckBoxCollection(name, data))
                                view.buildComponent(componentName)
                                // break or return doesnt work
                            })
                        } else {
                            dataSource?.push(componentName, ComponentDataCollection(name, values))
                            view.buildComponent(componentName)
                        }
                    })
                }
            }
    }
    because above code didnt work so i use imperative way.
    for (option in 0 until optionsSize) {
                val component = optionsGroup?.options?.get(option)
                if (component != null) {
                    val presentation: String? = component.presentation
                    val values = component.values
                    if (!TextUtils.isEmpty(presentation)) {
                        if (presentation == LifeComponentViewType.CHECKBOX) {
                            val data = transformCheckBoxValues(optionsGroup)
                            if (data.isNotEmpty()) {
                                dataSource?.push(presentation, ComponentDataCheckBoxCollection(optionsGroup.name, data))
                                view.buildComponent(presentation)
                                return
                            }
                        } else {
                            dataSource?.push(presentation!!, ComponentDataCollection(component.name, values))
                            view.buildComponent(presentation!!)
                        }
                    } else {
                        return
                    }
                }
            }
    does anyone have suggestions?
    b
    • 2
    • 4
  • b

    bj0

    11/09/2017, 3:25 AM
    interestingly, it's much easier to do it using an extension function on the interface:
    fun <T: Foo> T.common() = this
    s
    • 2
    • 2
  • d

    diesieben07

    11/09/2017, 9:05 AM
    @dragas Can you show the whole file?
    d
    i
    • 3
    • 5
  • f

    fatih.yalmanbas

    11/09/2017, 11:34 AM
    class x{
        val field;
    
        X?.foo(){
            this.field = doSomething();
        }
    }
    s
    • 2
    • 4
Powered by Linen
Title
f

fatih.yalmanbas

11/09/2017, 11:34 AM
class x{
    val field;

    X?.foo(){
        this.field = doSomething();
    }
}
s

snrostov

11/09/2017, 11:36 AM
this@x.field = doSometing()
(If I correctly understand what you need)
f

fatih.yalmanbas

11/09/2017, 11:37 AM
something like that
The real problem is that I am trying to add an extension function inside the same class (for null safe call on target)
even though function is tail recursive, compiler keeps telling me that it can not find a tail call
View count: 1