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

    David W

    05/19/2017, 9:08 AM
    https://developer.android.com/kotlin/get-started.html
    👍 2
    m
    • 2
    • 1
  • b

    blablupp

    05/19/2017, 9:38 AM
    The new Java stuff is nice, but to be true, code written with it simply looks ugly. In a big team with different skill levels, this leads to pure chaos.
    o
    m
    • 3
    • 3
  • t

    theopaintsil

    05/19/2017, 10:13 AM
    Are we going to have a beginner class ?
    v
    • 2
    • 3
  • m

    mipster

    05/21/2017, 4:44 PM
    so im trying to write a lambda function that returns a bool but the compiler think that it ment to return Unit anyone knows how i can fix it?
    {
    for (t in channels!!)
        if (t.item1 === message.channelReceiver)
            return false
        return true
    }
    i
    • 2
    • 1
  • m

    mipster

    05/21/2017, 4:53 PM
    so, like, you cant return in the middle of a lambda? only at the end?
    a
    • 2
    • 1
  • a

    alexreidy

    05/21/2017, 5:52 PM
    I think by "backing field" they just mean backing property. That confused me as well when reading through - if we're using strict language saying that everything is technically a "property" instead of a "field" then don't talk about fields in the same paragraph. Might be worth clarifying
    v
    • 2
    • 4
  • h

    harmony

    05/21/2017, 7:24 PM
    because now I have to use
    val x = y
    if (x != null) {}
    o
    g
    t
    • 4
    • 5
  • a

    apatrida

    05/21/2017, 11:37 PM
    @diesieben07 Java does bad things with generics a lot, Kotlin is very strict. The code you "cannot change" is bad and sets up an un-winnable situation for Kotlin. It isn't a bug in Kotlin. You give it a type T basically of
    *
    which means nothing useful. There is a big lack of information. At any point do you know what type T is? and if not, how does the
    parseProperty
    expect to work on unknown types, does it check against a list of instance types then performs its action? If there is no way to know outside of this function what type type is, then you need to change
    parseProperty
    to accept
    <*>
    as the type as well because you cannot say "give me a type T" to someone who can never know what is the type of
    T
    👍 1
    d
    • 2
    • 3
  • s

    swapper

    05/22/2017, 7:23 AM
    How do I map / use access modifiers concept of JAVA in kotlin? 🤔 Any pointers...
    :stackoverflow: 1
    j
    • 2
    • 2
  • n

    nawar

    05/22/2017, 2:47 PM
    Is it possible to pass the string data from the
    Sender
    class all the way to all the classes that implements
    Clickable
    interface Clickable {
        fun click(message: String)
    }
    
    class Sender {
       init {
           Clickable.click("sending from 'Sender'") // is this possible?
       }
    }
    
    class Button : Clickable {
        override fun click(message: String) = println("button $message") // receiving the message here
    }
    v
    d
    u
    • 4
    • 46
  • t

    trevjones

    05/22/2017, 3:22 PM
    when you use
    as?
    that will effectively wrap it in a try catch and return null if the cast fails
    o
    a
    • 3
    • 3
  • t

    trevjones

    05/23/2017, 8:52 PM
    I always do mine here: http://regexr.com/
    👍 2
    i
    • 2
    • 2
  • d

    Daniel

    05/24/2017, 8:16 AM
    Is there a equivalent to the replaceAll { } function on a ArrayList in Kotlin? (which mutates the array directly, when using for example a map { } I would have to assign the result back do the array or do a clear / addAll)
    a
    • 2
    • 4
  • d

    Daniel

    05/24/2017, 8:42 AM
    Ended up doing a extension myself, but would gladly replace it with a library function
    fun <T> ArrayList<T>.transformAll(transform: (T) -> T) {
        for(i in firstIndex..lastIndex) {
            this[i] = transform(this[i])
        }
    }
    @Test
        fun `Should apply the transformation to each element of the array list`() {
            // GIVEN
            val list = arrayListOf(2, 3, 4)
    
            // WHEN
            list.transformAll { it * 2 }
    
            // THEN
            assertThat(list, `is`(equalTo(arrayListOf(4, 6, 8))))
        }
    o
    a
    • 3
    • 7
  • m

    mrtreinis

    05/24/2017, 1:20 PM
    Am i missing something, or '\s' is not valid "single-space" in kotlin?
    g
    • 2
    • 6
  • e

    elect

    05/24/2017, 1:34 PM
    how to escape
    $
    in triple quote?
    g
    u
    • 3
    • 6
  • s

    sandeep

    05/25/2017, 6:18 PM
    Any idea what should go in those extension function?
    d
    • 2
    • 4
  • d

    Daniel

    05/25/2017, 7:53 PM
    Might there be a better way to convert a
    ArrayList<>
    to
    vararg
    parameters than
    *arrayList.toTypedArray()
    ?
    v
    • 2
    • 2
  • v

    voddan

    05/26/2017, 6:28 AM
    println((1..5).map {"*".repeat(it)}.joinToString(separator = "\n"))
    you don't get much more cryptic than that
    👍 4
    b
    • 2
    • 1
  • t

    tipsy

    05/26/2017, 6:02 PM
    @ice32 i made a web-framework for java/kotlin inspired by express.js: https://javalin.io/documentation
    👍 1
    i
    c
    j
    • 4
    • 25
  • d

    dierre

    05/27/2017, 1:55 PM
    to use both java and kotlin in the same project
    d
    • 2
    • 3
  • d

    deinspanjer

    05/27/2017, 1:58 PM
    I want to provide the methods that ScriptEngine provides as well as the methods that Invocable provides by delegating to either of those two objects.
    d
    • 2
    • 13
  • j

    jaspersmit

    05/29/2017, 12:28 PM
    anybody knows a nicer way to do this:
    val childUnitsById = units
                    .map { if(it.parent != null) it else null }
                    .filterNotNull()
                    .groupBy {it.parent!!}
    a
    m
    +2
    • 5
    • 23
  • m

    moehritz

    05/30/2017, 7:21 AM
    Hi! I got a custom self-made database library (java) which provides a
    SqlServer
    object for basically everything needed to interact with our database. In Java, we stored that reference in a static variable, as it was accessed and needed in a lot of different places. As there is no "static" in Kotlin, I'm unsure about how do do it properly.
    class Database { val sqlServer = SqlServer(...) }
    Does not work, as I can't access it from somewhere else
    class Database { companion object { val sqlServer = SqlServer(...) } }
    Does not work, as I can't pass any configuration
    object Database { val sqlServer = SqlServer(...) }
    Does not work, no support for constructors or similar
    In Java, we do this:
    public static void main(String[] args) {
      DbConfig dbCfg = new DbConfig(args);
    
      Database.init(dbCfg);
    
      //Database ready to use
      Database.select(...);
    }
    It would be nice to store the sqlServer object immutable and as a nonnull value. Maybe i'm just dumb rn, it's sort of my first kotlin project. 🙂 Thanks!
    d
    t
    n
    • 4
    • 11
  • c

    chi

    05/30/2017, 11:00 AM
    Hey guys, can I modify a private variable in a class via an extension of that class?
    v
    • 2
    • 3
  • d

    Daniel

    05/30/2017, 12:09 PM
    What tould be a good kotlin way to perform multiple (but same) comparisons with a object?
    fun isNewTarget(touched: Draft) = touched !== sourceTouched && touched !== targetTouched
    might it be possible to simplify this?
    d
    a
    • 3
    • 3
  • p

    pmckenzie

    05/30/2017, 2:32 PM
    and a more basic question, what do people use for unit testing?
    n
    n
    +3
    • 6
    • 12
  • h

    Holdge

    05/30/2017, 4:31 PM
    New to kotlin, wanna build kotlin from source and see how it works(eg: compiler or so), but I get problem when I try to build on my Mac OS, is there any tutorial in detail about build kotlin from source code?
    👍 2
    n
    d
    • 3
    • 20
  • a

    anstaendig

    05/30/2017, 6:19 PM
    Why the hell is the suppressing not working
    k
    • 2
    • 1
  • d

    dekee

    05/31/2017, 6:49 AM
    @perryprog try
    val hr = {
            for (i in 1..2) {
                for (k in 1..180)
                    print("—")
    
                println()
            }
        }
    
        println("Thing one")
        hr.invoke()
        println("Thing two")
        hr.invoke()
    p
    • 2
    • 1
Powered by Linen
Title
d

dekee

05/31/2017, 6:49 AM
@perryprog try
val hr = {
        for (i in 1..2) {
            for (k in 1..180)
                print("—")

            println()
        }
    }

    println("Thing one")
    hr.invoke()
    println("Thing two")
    hr.invoke()
p

perryprog

05/31/2017, 10:28 AM
dekee: My problem is I just want to call
hr
without parens. It’s not really a big deal, it would just look better. adding
.invoke()
is just longer than a regular function with
hr()
.
View count: 1