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

    orangy

    06/09/2017, 5:41 PM
    May be some #coroutines then? 🙂
    ➕ 1
    r
    • 2
    • 1
  • d

    dalexander

    06/09/2017, 6:12 PM
    I recently discovered on a project that at least on Android, creating a new Timer is equivalent co creating a new Thread, so you would probably want to have a threadpool or something you are dispatching to rather than creating a new Timer every time the method is called (depending on how frequently the method is called, of course).
    t
    • 2
    • 1
  • w

    witoldsz

    06/11/2017, 10:39 PM
    Strange things: Kotlin complains that my function has a parameter that is never used. What am I supposed to do with this warning? My function must have it declared or it won't comply to the interface. The compiler should not add a noise with such a useless warning.
    d
    a
    • 3
    • 55
  • j

    jasonlow

    06/12/2017, 2:12 AM
    and to begin with, how do I even write the expression to init the enum class?
    Color("red")
    does not work because
    enum types cannot be instantiated
    . And
    Color.valueof("red")
    throws me an
    illegal argument exception
    a
    • 2
    • 7
  • s

    sk0g

    06/12/2017, 12:34 PM
    Hey so, I don't have any Android experience yet, but I have done an intro to programming in Java and am currently in second year of Software Engineering. How hard would it be to get into making Android apps without much, if any, Java?
    d
    • 2
    • 7
  • r

    Ruckus

    06/12/2017, 3:03 PM
    You can use something like
    enum class People(value: Int) {
        man(1),
        baby(2),
        woman(3);
    
        companion object {
            fun byValue(value: Int) = values().firstOrNull { it.value == value }
        }
    }
    
    val people = People.byValue(3)
    if (people != null) {
        print("converted successfully => $people")
    } else {
        print("null value -> No Match")
    }
    n
    • 2
    • 2
  • t

    tulio

    06/12/2017, 4:22 PM
    Thanks for the answers, I think I will stick with the if version 🙂
    👍 1
    e
    • 2
    • 1
  • c

    cedric

    06/12/2017, 4:33 PM
    @tulio A few thoughts here: http://beust.com/weblog/2016/01/14/a-close-look-at-kotlins-let/ tldr: I tend to stick to
    if
    d
    t
    +3
    • 6
    • 11
  • c

    cedric

    06/13/2017, 4:14 PM
    @mmaillot No,
    Result
    is not a monad, it lacks a few things for that.
    o
    m
    • 3
    • 2
  • i

    igor.wojda

    06/13/2017, 11:44 PM
    Hey can somebody give me proper example why val may be not initialized at compile time (so we need to add
    const
    modifier) ?
    a
    • 2
    • 7
  • k

    kingvhit

    06/14/2017, 2:45 AM
    Sorry for my stupid question but does anybody let me know how can import synthetic automatically ? Like :
    import kotlinx.android.synthetic.main.activity_main.*
    Or any shortcut do it by your hand ?
    a
    • 2
    • 3
  • a

    alvico

    06/14/2017, 8:39 AM
    hey does anyone know about expert and good Kotlin teaches willing to give courses to interpresises in europe?
    j
    o
    • 3
    • 3
  • g

    gildor

    06/14/2017, 9:36 AM
    @jasonlow There is firstOrNull if you want to get nullable value. Reason - you can use
    first
    and get nonnull result
    j
    v
    m
    • 4
    • 20
  • a

    angloha

    06/14/2017, 4:52 PM
    Please i need book to learn Kotlin
    a
    p
    o
    • 4
    • 11
  • d

    darger

    06/14/2017, 7:32 PM
    Hello - I am trying to get started with Kotlin. I tried to download the command-line compiler - wget the download link on https://github.com/JetBrains/kotlin/releases/tag/v1.1.2-5 - it redirects to an obscure place on S3. All is probably fine but is it not possible to verify the integrity of the release in any way? Preferably via a GPG signature, alternatively via a SHA-2 digest?
    a
    • 2
    • 2
  • a

    akperkins1

    06/14/2017, 8:10 PM
    Hey guys, I want to learn Kotlin by contributing to some popular open source libraries on github. Does anyone have any suggestions?
    p
    • 2
    • 5
  • w

    witoldsz

    06/14/2017, 9:58 PM
    Hello! What is the easiest way to make Idea show me sources of Kotlin stdlibs? I was hoping the plugin will figure it out, but as of now all I can see are the signatures and
    Decompile to Java
    ,
    Choose sources
    . Should I download sources, unpack, point to Idea or the sources should be already somewhere? I am building project using Gradle, no cmd-line tools or other stuff installed.
    a
    • 2
    • 11
  • p

    punitjajo

    06/15/2017, 4:15 AM
    I’m building an online compiler for C, Python and Kotlin. C and Python work well, but Kotlin compilation takes a long time. Any feedback on how I can make the compilation faster? http://52.170.87.157:8079/kotlin.html
    n
    g
    e
    • 4
    • 5
  • e

    elect

    06/15/2017, 10:31 AM
    if I rewrite this
    fun findWindowSettings(name:String): IniData? {
        val id = hash(name, 0)
        return g.settings.firstOrNull { it.id == id }
    }
    as
    fun findWindowSettings(name:String) = g.settings.firstOrNull { it.id == hash(name, 0) }
    will be the
    hash()
    result cached or executed each time?
    m
    c
    • 3
    • 6
  • d

    duncanconroy

    06/15/2017, 2:16 PM
    Hi there, I'm new to Kotlin and currently writing a text file parser. I've come across the useful function File.forEachLine. What I want to do know, is to print out the progress of file reading, e.g. by getting the current file pointer. It seems that I can neither access the InputStream, which is used inside the forEachLine function, nor can I find another way of getting the current position in the file. Does someone know how I can get file position or currentLine / totalLines within forEachLine? Thanks in advance!
    i
    • 2
    • 2
  • i

    ishwerdas

    06/15/2017, 3:21 PM
    I am javascript developer, never worked in java.. and hence never worked on android development through traditional means ... any tips on how should I go about learning kotlin?
    v
    • 2
    • 5
  • m

    mmaillot

    06/15/2017, 4:02 PM
    I don't see the channel, thank you, i'll try that!
    j
    • 2
    • 2
  • c

    chuck

    06/15/2017, 4:33 PM
    For example, there are no implicit widening conversions for numbers ...
    Why not? https://kotlinlang.org/docs/reference/basic-types.html https://kotlinlang.org/docs/reference/basic-types.html#explicit-conversions
    d
    p
    • 3
    • 4
  • d

    daveroberts

    06/15/2017, 5:20 PM
    I'm looking at the Hello World build.gradle file. https://github.com/JetBrains/kotlin-examples/blob/master/gradle/hello-world/build.gradle I noticed that repositories and dependencies are listed twice, once in the buildScript and once in the root. Is there any documentation for why there are two? When I want to add a new dependency, does it need to go in one or both?
    a
    • 2
    • 1
  • b

    bryan

    06/16/2017, 5:40 AM
    case VALIDATE_PAIRING_KEY
    ?
    w
    • 2
    • 2
  • e

    evkaky

    06/16/2017, 8:09 AM
    guys, tail recursion is a so tasty optimization. Why it’s not turned on by default in kotlin? Why compiler can’t itself to recognize all cases for tail recursions in our code, and do appropirate stuff? Why do we need manually tolk to compiler via special keyword? (like “tailrec”). Tail recursion seems to be an ordinary optimization, like constant folding… and kotlin (and other langs) have no special keywords to turn constant folding optmiziations on!
    d
    • 2
    • 2
  • t

    thecipster

    06/16/2017, 10:54 AM
    Hi! I want to do something if a
    java.io.File
    variable is null or not readable. In Java this vould be
    if (myFile == null || !myFile.canRead()) {
        // error!
    }
    which works always because of short-circuit evaluation. IntelliJ translates the above code to:
    if (simDesc == null || !simDesc!!.canRead()) {
        // error!
    }
    which is a bit ugly IMHO. Any idea on making it more idiomatic?
    k
    u
    • 3
    • 11
  • v

    voddan

    06/16/2017, 11:40 AM
    Maybe you want to use an
    if
    inside the
    when
    ?
    is String -> if("HELLO".equals(obj.toUpperCase()))) println("Greeting")
    s
    • 2
    • 1
  • k

    ktw

    06/16/2017, 1:21 PM
    I installed 1.1.3 EAP in Intellij, but now the REPL keeps freezing. Any way to get back to 1.1.2?
    m
    • 2
    • 2
  • p

    perryprog

    06/16/2017, 3:35 PM
    Jun 16, 2017 11:34:03 AM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
    INFO: Discovered TestEngines with IDs: [spek]
    Exception in thread "main" java.lang.AbstractMethodError: Method org/jetbrains/spek/engine/Scope$Group.isTest()Z is abstract
    	at org.jetbrains.spek.engine.Scope$Group.isTest(Scope.kt)
    	at org.junit.platform.engine.TestDescriptor.hasTests(TestDescriptor.java:160)
    	at org.junit.platform.launcher.core.Root.lambda$static$0(Root.java:33)
    	at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:179)
    	at org.junit.platform.engine.TestDescriptor.lambda$accept$0(TestDescriptor.java:181)
    	at java.lang.Iterable.forEach(Iterable.java:75)
    	at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:181)
    	at org.junit.platform.launcher.core.Root.lambda$acceptInAllTestEngines$2(Root.java:85)
    	at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608)
    	at org.junit.platform.launcher.core.Root.acceptInAllTestEngines(Root.java:85)
    	at org.junit.platform.launcher.core.Root.prune(Root.java:77)
    	at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
    	at org.jetbrains.spek.tooling.runner.junit.JUnitPlatformSpekRunner.run(JUnitPlatformSpekRunner.kt:107)
    	at org.jetbrains.spek.tooling.MainKt.main(Main.kt:58)
    j
    • 2
    • 4
Powered by Linen
Title
p

perryprog

06/16/2017, 3:35 PM
Jun 16, 2017 11:34:03 AM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: Discovered TestEngines with IDs: [spek]
Exception in thread "main" java.lang.AbstractMethodError: Method org/jetbrains/spek/engine/Scope$Group.isTest()Z is abstract
	at org.jetbrains.spek.engine.Scope$Group.isTest(Scope.kt)
	at org.junit.platform.engine.TestDescriptor.hasTests(TestDescriptor.java:160)
	at org.junit.platform.launcher.core.Root.lambda$static$0(Root.java:33)
	at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:179)
	at org.junit.platform.engine.TestDescriptor.lambda$accept$0(TestDescriptor.java:181)
	at java.lang.Iterable.forEach(Iterable.java:75)
	at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:181)
	at org.junit.platform.launcher.core.Root.lambda$acceptInAllTestEngines$2(Root.java:85)
	at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608)
	at org.junit.platform.launcher.core.Root.acceptInAllTestEngines(Root.java:85)
	at org.junit.platform.launcher.core.Root.prune(Root.java:77)
	at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
	at org.jetbrains.spek.tooling.runner.junit.JUnitPlatformSpekRunner.run(JUnitPlatformSpekRunner.kt:107)
	at org.jetbrains.spek.tooling.MainKt.main(Main.kt:58)
j

jk

06/16/2017, 3:42 PM
perryprog: it's best to direct these questions on #spek
p

perryprog

06/16/2017, 3:42 PM
I didn’t know that existed, thanks!
j

jk

06/16/2017, 3:43 PM
this issue is: https://github.com/JetBrains/spek/issues/195#issuecomment-300645464 basically you need to add:
testRuntime 'org.junit.platform:junit-platform-launcher:1.0.0-M4'
p

perryprog

06/16/2017, 3:44 PM
Thanks again!
View count: 2