https://kotlinlang.org logo
Docs
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
  • r

    Ruckus

    05/08/2018, 4:10 PM
    arr.associate { it to f(it) }
    👍 1
    e
    • 2
    • 1
  • m

    Michael

    05/08/2018, 6:40 PM
    What’s the right way to do a Data Class such that it can “implement an interface that requires one getter”? The data class is just doing what it’s doing, I just need to pass it to a method that requires one getter (which it would have)
    s
    • 2
    • 18
  • r

    Russell Davis

    05/08/2018, 11:28 PM
    Can a mod ban that account? (spammed a ton of different channels with that same message, not relevant or appropriate) (edit: moving to #meta)
    👍 1
    k
    • 2
    • 2
  • a

    Aregev2

    05/09/2018, 5:38 AM
    Can I access jni via kotlin (where is the native keyword)
    w
    • 2
    • 1
  • a

    arekolek

    05/09/2018, 8:11 AM
    this should work:
    inline fun <reified K, reified V> Any?.asLinkedMap(): LinkedHashMap<K, V>? {
        return (this as? Map<*, *>)
                ?.takeIf {
                    it.entries.all { (key, value) -> key is K && value is V }
                }
                ?.map { (key, value) -> Pair(key as K, value as V) }
                ?.toMap(LinkedHashMap())
    }
    w
    • 2
    • 5
  • r

    Ruckus

    05/09/2018, 3:22 PM
    (All the
    TuplesN
    classes have package private constructors, with the
    Tuples
    class providing static methods for creating them.)
    v
    • 2
    • 1
  • r

    Ruckus

    05/09/2018, 3:33 PM
    I don't have any experience with mockito, but you can try asking in #mocking
    z
    n
    j
    • 4
    • 26
  • m

    Marc Steven

    05/10/2018, 8:14 AM
    Is it great to develop new project using kotlin?I am new here from iOS development
    💯 2
    s
    p
    • 3
    • 2
  • a

    Andrei

    05/10/2018, 9:36 AM
    is this a intended behavior of .withDefault? It appears the only case I can actually get the default is by using .getValue
    a
    • 2
    • 4
  • s

    sudhanshu singh

    05/10/2018, 10:36 AM
    is there any difference in these two approaches?
    Utils.Kt
    object Utils {
          fun doSomething(){
    }
    
    vs
    
    Utils.Kt
    fun doSomething(){
    }
    a
    k
    • 3
    • 6
  • d

    dagguh

    05/10/2018, 1:55 PM
    https://kotlinlang.org/docs/reference/delegation.html
    Note, however, that members overridden in this way do not get called from the members of the delegate object, which can only access its own implementations of the interface members
    This behavior is the opposite of what a manual delegation pattern does. What’s the rationale behind this difference?
    a
    • 2
    • 14
  • w

    wineluis

    05/10/2018, 1:58 PM
    is there a pure kotlin web server/framework?
    a
    • 2
    • 3
  • t

    tylerwilson

    05/10/2018, 2:25 PM
    Generics Question: I want to constrain a type in a class such that the type supports arithmetic operations, like so:
    data class Item<T>(val operand1: T, val operand2: T) {
          val result: T = operand1 / operand2
    }
    But it gives me errors about BigDecimal (I guess this is the first class it tried to match. So I need to constrain T to be only types that support division, like T: Number, T: divideBy or something. Is this possible in Kotlin? Thank you!
    a
    • 2
    • 6
  • d

    droidrcc

    05/10/2018, 2:39 PM
    @araqnid, the type at line 26 is java.util.List<? extends T>
    a
    • 2
    • 3
  • s

    SackCastellon

    05/10/2018, 10:41 PM
    I'm trying to convert
    java.time.LocalDateTime
    to
    org.joda.time.DateTime
    and back, so far I have created this extensions which seem to work fine:
    fun java.time.LocalDateTime.toJoda(): org.joda.time.DateTime = DateTime(this.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())
    fun org.joda.time.DateTime.toJava(): java.time.LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(this.millis), ZoneId.systemDefault())
    The LocalDateTime is used by JavaFX's DatePicker, and the DateTime is used by Exposed. Any comments or suggestions?
    a
    • 2
    • 2
  • s

    sngrekov

    05/11/2018, 7:20 AM
    @Daniel It doesn't have to. But you will lose check in when expression.
    d
    • 2
    • 2
  • r

    robstoll

    05/11/2018, 1:02 PM
    is there a way to force the user to pass a nullable type? Say I have
    fun foo(s: String?){}
    is there a way to force that one has to pass
    String?
    and cannot pass
    String
    ?
    a
    • 2
    • 30
  • y

    ylemoigne

    05/11/2018, 1:42 PM
    Hum wanted to add a comment on a YT ticket, and got
    Workflow kotlin-pull-requests reports error: TypeError: Cannot call method "indexOf" of null (kotlin-pull-requests/on-pull-request-link-add-tag-make-major#17)
    Contact project admin Andrey Breslav
    on post.
    👀 1
    s
    • 2
    • 2
  • r

    Ruckus

    05/11/2018, 8:10 PM
    package demo
    
    val name = "package"
    
    fun main(args: Array<String>) {
        val name = "local"
    
        class Test {
            val name = "class"
            val a get() = name  // returns "local"
            val b get() = this.name  // returns "class"
            val c get() = demo.name  // returns "package"
        }
    }
    m
    • 2
    • 4
  • r

    Ruckus

    05/11/2018, 8:53 PM
    Why are
    any
    and
    all
    defined on
    Array<out T>
    instead of
    Array<T>
    ?
    k
    i
    • 3
    • 12
  • d

    Danny

    05/11/2018, 8:59 PM
    Hey there, is anyone working with
    kotlin-reflect
    on Windows? We were running into an issue where windows 10 defender is marking
    kotlin-reflect-1.2.41
    as a virus of type
    Trojan:Win32/Vigorf.A
    🧐 1
    😵 1
    g
    a
    h
    • 4
    • 11
  • o

    osamarao

    05/11/2018, 10:47 PM
    @eric Cache how ?
    e
    • 2
    • 3
  • f

    frellan

    05/12/2018, 1:45 PM
    Hi! I have a general question, I am trying to write a function that takes a class variable as a parameter and then returns a list of objects with that class, how do one do that in kotlin? I want to do this:
    fun findAll(modelClass: KClass<out BaseModel>): List<modelClass> {
      return Ebean.find(modelClass::class.java).findList()
    }
    But that obviously is not the right syntax
    a
    • 2
    • 21
  • p

    Pere Casafont

    05/12/2018, 7:00 PM
    hi, I have a set of xml files with tons of static data (350,000 lines) which need maintenance and version control; is kotlin DSL an option here? Or intellij/compile times will be destroyed?
    c
    e
    • 3
    • 14
  • k

    kenkyee

    05/13/2018, 7:02 PM
    Does anyone know if Kotlin can be used in a project w/ the Pants build system? All I could dig up was an old tweet from JW: https://twitter.com/jakewharton/status/858156967742889984?lang=en But there's nothing in the Pants docs about Kotlin, so it seems there's no official support yet?
    o
    • 2
    • 2
  • a

    arekolek

    05/13/2018, 7:23 PM
    Is there any way to make Kotlin understand that this
    when
    expression is exhaustive?
    fun test(x: Int): Int {
            assert(x in 1..3) // doesn't help
            if (x !in 1..3) throw IllegalArgumentException()  // doesn't help
            return when (x) {
                1 -> -1
                2 -> 0
                3 -> 1
            }
        }
    a
    f
    • 3
    • 14
  • m

    muralimohan962

    05/14/2018, 9:24 AM
    Hi! How can i consume extensions from Java?
    h
    • 2
    • 2
  • j

    jackjill

    05/14/2018, 1:26 PM
    any
    ktor
    users here ??
    s
    • 2
    • 1
  • j

    juliocbcotta

    05/14/2018, 2:57 PM
    Hi, how can I access a generic type T for a class ?
    abstract class TestCase<T : Activity>() {
        val classz = (javaClass
                .genericSuperclass as ParameterizedType).getActualTypeArguments()[0] as Class<T>
        @Rule
        @JvmField
        val rule = IntentsTestRule(classz, false, false)
    	}
    This seems to work to
    open FooTestCase: TestCase<ActivityA>
    , but not to
    BarTestCase: FooTestCase
    ...
    a
    d
    • 3
    • 8
  • a

    Andrei

    05/14/2018, 3:20 PM
    Is it by any chance possible to use .trimMargin() on
    const val
    ?
    a
    s
    k
    • 4
    • 11
Powered by Linen
Title
a

Andrei

05/14/2018, 3:20 PM
Is it by any chance possible to use .trimMargin() on
const val
?
a

Andreas Sinz

05/14/2018, 3:21 PM
const val foo = """ some text """.trimMargin()
?
s

Shawn

05/14/2018, 3:21 PM
I’m pretty certain that won’t work
in order for a value to be
const
it needs to be a string or a primitive that the kotlin compiler can inline where the
val
is used
a

Andreas Sinz

05/14/2018, 3:22 PM
yeah, it needs to be a constant
a

Andrei

05/14/2018, 3:22 PM
It won't work as this because it's compile-time
May be an other way exists
k

karelpeeters

05/14/2018, 3:24 PM
There isn't any compile time evaluation yet.
s

Shawn

05/14/2018, 3:24 PM
you’d have to have a version of your string already trimmed if you need it to be
const
which isn’t really necessary unless you’re passing some large string to an annotation or something 🤔
a

Andrei

05/14/2018, 3:24 PM
so no compile-time trimming of any sort?
s

Shawn

05/14/2018, 3:24 PM
not yet anyhow
View count: 3