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

    aviran

    12/28/2019, 7:51 PM
    How do I access the IntRange instance from within the ExposureSelector function>?
    t
    m
    • 3
    • 2
  • k

    kyleg

    12/28/2019, 10:14 PM
    (Also asked in #general and #intellij ) In Intellij when I run my application, it finds my
    src/main/resources/logback.xml
    and logs correctly, but when I build a fat jar to run on my production, there is no logging whatsoever. I can only assume the
    logback.xml
    is not being found. But I have set up Intellij to include it in the build via the Module settings. How does one get logback to work with an artifact?
    👎 1
    :stackoverflow: 1
    n
    q
    m
    • 4
    • 20
  • j

    James Richardson

    12/29/2019, 1:04 PM
    This is a very difficult question to answer! Like most libraries the possibilities are almost limitless and any limitations may be irrelevant to you. The way I tend to work is just use something that helps me do whatever it is that I am trying to do... so if you can expand on your use case it would help figure out if it's a suitable technology....
    p
    • 2
    • 2
  • m

    Michał Kalinowski

    12/30/2019, 3:28 PM
    can I restrict somehow type of generics for example I would like implement `
    class Angle<T>
    where T can be Int or Float or Double and nothing else
    d
    m
    i
    • 4
    • 9
  • k

    kyleg

    01/03/2020, 7:11 AM
    @bjonnh I can’t tell the full context from what you posted (is this just the Boolean implementation? Or is the presence of
    Boolean
    in your code because the function must always deal with Boolean no matter which type of Term?) Assuming the pastebin contains the Output that only deals with Boolean, then why not
    class Output<U: Term<V>, V>(val name: String) {
       private val callbacks: MutableList<suspend (U) -> V> = mutableListOf()
       // ...
    }
    and then have
    class Term
    be
    class Term<V>
    instead? I’m a relative neophyte with generics, though, so could be wrong. Plus I don’t have all your code, so maybe my suggestion doesn’t work anyway.
    b
    • 2
    • 5
  • w

    Will Nixon

    01/03/2020, 2:49 PM
    Hi all, is there any way to add a custom
    Fling Listener
    to a
    RecyclerView
    without creating a new RecyclerView class?
    d
    • 2
    • 2
  • a

    A

    01/04/2020, 8:30 PM
    hi ,i am a beginner in kotlin. I have been making android apps gor a long time , so should i start learning kotlin from scratch (like the way i learned java first) or should i focus on the Android part of kotlin?
    k
    b
    +3
    • 6
    • 7
  • b

    bbaldino

    01/06/2020, 5:23 PM
    Is there any support for warning/erroring on an unused return value in kotlin? I found this thread https://discuss.kotlinlang.org/t/unused-result-warnings/602/5 but it's quite old, wondering if anything's changed since then. Everything I find when searching is related to unused arguments.
    b
    k
    • 3
    • 4
  • i

    Imany

    01/06/2020, 6:09 PM
    What is main reason for having
    with
    and
    apply
    ?
    s
    p
    m
    • 4
    • 3
  • r

    Ricjhill

    01/10/2020, 1:20 PM
    Is it recommended to mix Property-based Testing and Behavior Spec when using https://github.com/kotlintest
    m
    r
    • 3
    • 5
  • g

    gabrielfv

    01/10/2020, 8:37 PM
    Hello, I have a result-pattern-like generic sealed class, I'd like to define objects that represent possible values that are independent of the type specified, is it possible?
    sealed class State<out T : Any>
    object Loading : State</* Type isn't relevant here */>()
    data class Loaded<T : Any>(data: T) : State<T>()
    There's no reason for
    Loading
    not to be an object in this context, neither is there any reason for it to specify a type. Changing the variance to contravariance and making it an
    Any
    is a design flaw in this scenario. Is there any convenient alternative to what I'm trying to accomplish here?
    s
    m
    • 3
    • 5
  • b

    bbaldino

    01/10/2020, 8:58 PM
    Is the only way to get the KClass of a List type (say,
    List<Int>
    ) to do
    listOf<Int>().javaClass.kotlin
    ? I get complaints trying to do
    List<Int>::class
    m
    • 2
    • 8
  • o

    oday

    01/11/2020, 5:38 PM
    how do I stick to keeping each class member immutable and still change the fields and modify them as I please?
    k
    j
    • 3
    • 2
  • o

    oday

    01/11/2020, 5:38 PM
    every time I assign the object back to a copy of itself with the changed fields?
    b
    d
    • 3
    • 7
  • j

    johnfn

    01/11/2020, 11:44 PM
    if (key in batches) {
            batches[key].add(entity)
          }
    r
    • 2
    • 1
  • j

    johnfn

    01/11/2020, 11:50 PM
    if (!batches.containsKey(key)) {
      batches[key] = emptyValue;
    }
    
    batches[key].add(entity);
    r
    • 2
    • 3
  • j

    Jérôme Gully

    01/13/2020, 8:49 AM
    if (message.fileDescriptor?.isImageType ?: false)
    Is there a better way to write that ? because
    fileDescriptor
    can be null, i'm forced to write
    ?: false
    , maybe kotlin as a sugar syntax to avoid the
    ?: false
    like "if this is null, it's false"
    m
    • 2
    • 3
  • o

    oday

    01/14/2020, 12:09 PM
    hi, how can I refactor this with
    indices
    val n = arr.size
        for (i in 0 until n - 1) {
            for (j in 0 until n - i - 1) {
    m
    • 2
    • 3
  • m

    Mark

    01/15/2020, 3:12 AM
    Suppose I have a list of lambdas like:
    List<(Int) -> Unit>
    but I’d rather be more explicit so define an
    interface MyFun: (Int) -> Unit
    so that my list now looks like
    List<MyFun>
    . However, now, to create such a
    MyFun
    , I need to do something like
    object: MyFun { override invoke(val: Int) { //some stuff } }
    . Does this mean I’m creating an extra object compared to with not using the interface? If so, is there a better way?
    r
    d
    a
    • 4
    • 5
  • m

    Mark

    01/16/2020, 2:45 AM
    Destructuring: Suppose I have a function like this:
    fun childVisible(left: Int, top: Int, right: Int, bottom: Int): Boolean
    and I want to pass in the properties of an Android
    Rect
    . Is there a way to do the following more concisely?
    val (childLeft, childTop, childRight, childBottom) = childRect
    return childVisible(childLeft, childTop, childRight, childBottom)
    a
    m
    +2
    • 5
    • 8
  • e

    Esa

    01/16/2020, 11:47 AM
    Hi, need a bit of help with where to start on refactoring my code. The code performs a list of tasks. The list itself is quite huge, so I’ve `.chunk()`’ed the list into smaller chunks. Each of these chunks I then start each task asynchronously, and await them all before continuing to the next chunk. I concider this a cheap hack by someone who doesn’t actually know how to implement parallellism fully.. If I instead want to convert this into a pool, that
    n
    amount of workers can pick tasks from, where do I start? Java has ThreadPool, what do we have when we use coroutines instead? The reason I want to convert it to a pool with fixed size of tasks to be run concurrently is because in my current
    .awaitAll()
    -implementation I rarely have all workers working simultaneously, but very often only half or less working because the other half is already completed, leading to a very inefficient implementation. The tasks themselves involve api-calls to the same destination, so some kind of throttling is very important. What I am looking for is someone to tell me what these concepts are called so I can do the googling more efficiently 🙂 Thanks in advance.
    d
    t
    • 3
    • 12
  • g

    glade

    01/16/2020, 7:13 PM
    Hello All — Happy to be part of this community! We’re beginning to adopt Kotlin as our backend language and our intermediate language for datamodels/common configuration/constants. Maybe I can be redirected to the right channel. I’m trying to setup either a multiproject build or a composite build which allows me to transpile several of our datamodels into javascript and to the jvm. I’m currently blocked by the js project depending on a jvm project but disliking it. Finding documentation has been a tough because there’s so many outdated repositories and tutorials out there across gradle versions and kotlin versions. (The kotlin docs could use a version selector so we aren’t given so many caveats about crazy version matrices.) My current error is this
    Could not determine the dependencies of task ':models-js:compileKotlinJs'.
    > Could not resolve all task dependencies for configuration ':models-js:compileClasspath'.
       > Could not resolve project :models.
         Required by:
             project :models-js
          > Unable to find a matching variant of project :models:
              - Variant 'apiElements' capability com.gigwell.shared.models:models:1.0:
    Can someone recommend a recently updated project (hopefully on 1.3.61+) and Gradle 5/6 that demonstrates this? The closest I found is kotlin-todomvc but its still using
    "org.jetbrains.kotlin.frontend"
    Cheers
    s
    r
    m
    • 4
    • 12
  • g

    glade

    01/16/2020, 9:53 PM
    This unable to find matching variant is the real error when models-js is trying to reference code from models. Models is jvm. If I change its type to js, the build completes. I need to use ‘models’ in both contexts.
    • 1
    • 1
  • m

    Mark

    01/19/2020, 2:23 PM
    Is there a more concise way to specify this range
    x..x+y
    ?
    a
    e
    • 3
    • 8
  • b

    bum

    01/20/2020, 6:14 PM
    Hi, think its a stupid question but do we need to install
    kotlin.test
    from somewhere else? For what I understood the references says
    kotlin.test
    is a core library (https://kotlinlang.org/api/latest/kotlin.test/index.html) but when I try to use
    @Test
    annotation, Intellij tells me it is not defined What should I do to use kotlin.test library? Thanks in advance.
    d
    • 2
    • 2
  • n

    nfrankel

    01/20/2020, 6:24 PM
    kotlin.test
    library provides annotations to mark test functions and a set of utility functions for performing assertions in tests, independently of the test framework being used.
    emphasis on “library” it’s not part of kotlin per se so it should be used through your usual build tool cf. https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-test/1.3.61
    👍 1
    b
    k
    • 3
    • 2
  • f

    frogger

    01/21/2020, 10:12 AM
    what is the ideomatic way to get a copy of an Array without element
    n
    ?
    e
    s
    +2
    • 5
    • 22
  • w

    Wesley Acheson

    01/21/2020, 3:01 PM
    I don't know correct channel to post this question. I'll delete from getting started if it belongs only in spring. I'll delete from spring if it belongs only in getting started.
    • 1
    • 1
  • n

    Nikola Milovic

    01/21/2020, 3:31 PM
    Trying to get into testing and start writing efficient and proper tests. Any links/ tutorials/ repos that can be helpful? Looking for good learning references.
    m
    • 2
    • 2
  • m

    MartinZaubitzer

    01/21/2020, 10:59 PM
    Hi, I try to generate documentation using Dokka. Worked out great, but there is no specific format for GitlabWiki docs. Can someone please explain a little more in depth how I can create my own format? I know about this: https://github.com/Kotlin/dokka/issues/279 But it is not really helping me. I am unsure where to start and what actual to do. Thanks.
    c
    • 2
    • 4
Powered by Linen
Title
m

MartinZaubitzer

01/21/2020, 10:59 PM
Hi, I try to generate documentation using Dokka. Worked out great, but there is no specific format for GitlabWiki docs. Can someone please explain a little more in depth how I can create my own format? I know about this: https://github.com/Kotlin/dokka/issues/279 But it is not really helping me. I am unsure where to start and what actual to do. Thanks.
c

Casey Brooks

01/21/2020, 11:05 PM
Custom formats for Dokka aren’t for the faint-of-heart, currently, but it can be done. I maintain a project that uses Dokka to create JSON-formatted output, and you’re welcome to browse the source and copy my setup for yourself, though it’s probably much more customized than you’d want it for Markdown output https://github.com/copper-leaf/kodiak
An alternative you might consider is using my other project, Orchid, to generate a full website, rather than just a wiki. It supports deploying to GitLab Pages, and renders nicer-looking Kotlin docs alongside your wiki docs. strikt.io is a good example of a project site documented with Orchid, and you can follow this tutorial to get started https://orchid.run/wiki/learn/tutorials/how-to-document-kotlin
m

MartinZaubitzer

01/21/2020, 11:27 PM
Ok thanks, I will try with Gitlab Pages. Does Orchid support Android? I have tried setting it up and got stuck with: "The java plugin has been applied, but it's not compatible with the android plugins"
c

Casey Brooks

01/22/2020, 12:00 AM
You’ll want to set the Orchid project up in a different subproject and point it to your Android modules
👍 1
View count: 2