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

    Marc Knaup

    08/08/2020, 5:24 PM
    What is the reason that it’s not possible to provide interface function default implementations for
    toString()
    and alike? That would be super helpful 🙂
    p
    n
    • 3
    • 7
  • f

    frank

    08/08/2020, 9:33 PM
    @Alexey Belkov [JB], What are the differences between versions of the libraries that have K*otlin_version* specified and those that do not? Sample in Ktor:
    1.3.2-$kotlin_version
    vs
    1.3.2
    . Both work it
    t
    n
    • 3
    • 2
  • j

    Jonny

    08/08/2020, 10:58 PM
    I'm still new to Android development and now I'm getting started with Clean Architecture and I'm wondering about some things. First of all I'm using a single activity pattern and am in the process of modularizing my project by features and adding usecases. I've got a couple of questions if anyone's got some time. 1. What's a good level of dividing features? Could one feature have multiple associated fragments? 2. I find myself not creating repositories for most features. Instead I have 3 repos in the app module, because they must be used in multiple places of the project. Is this right or wrong? 3. How would I handle things like someone sending me a message when that logic will only happen once I'm in an assignment together with that person. This would require that I'm somehow notified about the message in multiple fragments. I would need to observe the same data in multiple viewmodels, use an extra activity, or put the livedata observing in the main viewmodel. This would quickly make the mainviewmodel full of stuff it only needs in certain areas of the app. I have a similar requirement for other areas of the app where I need to receive notifications in the form of popups across certain fragments. Thanks.
    s
    j
    • 3
    • 3
  • t

    TwoClocks

    08/09/2020, 4:58 AM
    is there a list type where you can insert into the middle? either before or after a element, or at an index? any of the above?
    d
    e
    t
    • 4
    • 36
  • i

    iseki

    08/09/2020, 12:17 PM
    Are there any plan to improve the experience of the REPL?
    • 1
    • 1
  • v

    vpriscan

    08/10/2020, 8:37 AM
    Kotlin docs say
    i in 1..4
    is equivalent of
    1 <= i && i <= 4
    , but is it really on the bytecode level? Doesn't range expression generate an additional range object?
    e
    l
    n
    • 4
    • 5
  • m

    marcinmoskala

    08/10/2020, 9:47 AM
    Do you think the fact that bounded property reference is not lazy is an error? For me it should be, and
    lazy { a.makeB() }
    should be the same as
    lazy(a::makeB)
    https://blog.kotlin-academy.com/method-references-and-lambdas-in-lazy-properties-371dbbea857b
    🇳🇴 2
    👍 1
    a
    i
    • 3
    • 3
  • c

    Chris Cordero

    08/10/2020, 11:48 PM
    Is it bad to call a blocking function from inside a coroutine?
    z
    n
    • 3
    • 5
  • m

    Manit Chitkara

    08/11/2020, 8:20 AM
    Hey Guys Actually i'm getting a little frustrated learning kotlin please tell something to boost me up!!
    k
    m
    +5
    • 8
    • 12
  • s

    StavFX

    08/11/2020, 6:07 PM
    Is there a way to pass a generic parameter to a (secondary) constructor? If it was any other method, I would do
    fun <T> foo(param: T)
    , but with a constructor I can’t just do
    <T> constructor(param: T)
    There are ways I can get around this limitation, but I’m just curious if it’s possible with slightly different syntax. (also, I don’t want to make the entire class generic to
    T
    )
    s
    n
    e
    • 4
    • 13
  • j

    Juan Medina

    08/11/2020, 6:44 PM
    Hi there, I'm new in the community 🙂
    🤩 1
    👋 10
    🖖 1
    🎉 11
    a
    • 2
    • 1
  • j

    Jorrit

    08/12/2020, 2:20 PM
    How do I pass the constructor of a nested class?
    class Base() {
        class Nested() {
        }
    }
    
    funWithCtor(::Base) // works
    funWithCtor(::Base.Nested) // doesn't work
    funWithCtor(::Nested) // works if: import Outer.Nested
    m
    d
    • 3
    • 20
  • h

    Hanno

    08/13/2020, 9:12 AM
    Hey :) i know there's an option to tell kotlin which bytecode level to produce. Is there anything that also prevents from compiling against jdk stuff from above the specified version? With java, there is the --release flag, which is also nicely supported by gradle 6.6 now. We need to be able to use jdk for example 11, but our application has to run on java 8. Thanks in advance for any hints :)
    n
    i
    a
    • 4
    • 6
  • l

    laht

    08/13/2020, 11:21 AM
    Hi, I just want to check if I'm in progress of solving something that does not need solving. I want users to be able to run kotlin scripts out of the box (no pre-installation requirements) with (runtime) maven dependency resolution. So I made https://github.com/markaren/kts yesterday. It allows users to download the
    kts
    executable and then invoke a
    .kts
    script with maven dependencies. I know of kscript (unix systems) and the official scripting support (needs kotlin installed). My solution requires no prior software installed and works regardless of platform. Is it valuable?
    b
    • 2
    • 35
  • i

    ilya.gorbunov

    08/13/2020, 3:15 PM
    📣 It's
    2020-08-13T15:15:00Z
    , a good time to announce the first milestone of kotlinx-datetime library, v0.1, has been published https://discuss.kotlinlang.org/t/kotlinx-datetime-0-1-has-been-published/18766
    ❤️ 2
    🎊 7
    👍 7
    🎉 39
    d
    n
    +6
    • 9
    • 23
  • s

    stanislav.erokhin

    08/13/2020, 3:38 PM
    We are starting the 1.4.0 release activities. Please be patient, it will take a bit of time. It will be officially out only after the blog post appears in blog.jetbrains.com/kotlin. In the next couple of days you may see new artifacts appear in various repositories. Since we don’t have full control of all the systems involved, you may temporarily observe an inconsistent state of the 1.4.0 world. Please don’t be alarmed, the blog post will notify you when we reach a consistent state 🙂 Looking forward to your feedback on 1.4.0 when it’s ready. Have a nice Kotlin!
    🎉 78
    :kotlin-flag: 19
    💃 1
    🕺 2
    🎊 19
    l
    a
    • 3
    • 4
  • a

    Andrea Giuliano

    08/13/2020, 7:19 PM
    Hi folks, how would you write in kotlin a function that execute a function based on a percentage. Say for example you get a function to be called millions of times, and based on a param (the fixed percentage) you execute it. Something like: FunctionLimiter.execute(function, 10%) //function will be called only 10% of the times
    n
    c
    n
    • 4
    • 39
  • k

    kevin.cianfarini

    08/13/2020, 8:12 PM
    Should my
    commonTest
    module be able to see
    internal
    code from
    commonMain
    ? Are they part of the same compile group?
    r
    a
    • 3
    • 19
  • n

    nathan

    08/13/2020, 8:34 PM
    anyone familar with spring boot with kotlin?
    t
    e
    +2
    • 5
    • 6
  • a

    Alex Ch

    08/13/2020, 8:58 PM
    Where should I report a problem with experimental API? Specifically for 
    @ExperimentalUnsignedTypes
    ?
    z
    • 2
    • 3
  • а

    Артём Гильмудинов

    08/14/2020, 8:55 AM
    Hello. Does anybody know why ktor by default disables okhttp redirects? https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-okhttp/jvm/src/io/ktor/client/engine/okhttp/OkHttpConfig.kt#L16 It is strange because okhttp enables redirects by default.
    s
    e
    • 3
    • 6
  • m

    Mgj

    08/14/2020, 9:03 AM
    Im struggling a bit with reified generics. I have a class that needs to call a 3rd party inline function. I want a method in my class to be generic and pass the generic type to the inline function but i cannot do this:
    class MyClass {
            suspend fun <T> doStuff(): T {
                return myReified<T>()
            }
        }
    
    suspend inline fun <reified T> myReified(): T
    What is a good workaround?
    d
    • 2
    • 6
  • d

    dfriehs

    08/14/2020, 10:09 AM
    Can someone tell me what I am doing wrong? I would like to use contracts to hide the type check, but the smart cast either doesn't work, or something like this happens:
    d
    • 2
    • 3
  • a

    Andrea Giuliano

    08/14/2020, 12:41 PM
    Hi folks, quick question. Why I can’t convert a sequence into a java stream like this
    sequence {
       yieldAll(1..100 step 10)
    }.asStream()
    while in the <http://(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.streams/kotlin.sequences.-sequence/as-stream.html|doc> it seems it’s possible? Intellij tells me
    unresolved reference asStream()
    d
    d
    • 3
    • 8
  • f

    Fudge

    08/14/2020, 1:17 PM
    Is there a way to supress warnings for an entire project? The point is to supress "unused" warnings in a library.
    d
    a
    • 3
    • 3
  • e

    Eugen Martynov

    08/14/2020, 2:05 PM
    Is 1.4 released?
    d
    • 2
    • 2
  • v

    Volodymyr Galandzij

    08/14/2020, 2:42 PM
    Hi, is there any idea why this doesn't compile?
    typealias AndroidUri = android.net.Uri
    val builder = AndroidUri.Builder()
    ==>
    Unresolved reference: Builder
    This one works as expected:
    typealias AndroidUriBuilder = android.net.Uri.Builder
    val builder = AndroidUriBuilder()
    a
    • 2
    • 2
  • s

    Slackbot

    08/14/2020, 3:42 PM
    This message was deleted.
    n
    p
    • 3
    • 7
  • t

    TwoClocks

    08/14/2020, 9:18 PM
    since enums can't have variables/properties (can they?) is seal classes how people generally simulate union types?
    s
    n
    j
    • 4
    • 45
  • d

    DALDEI

    08/15/2020, 3:45 PM
    'reified' constructor type parameters ? Possible ? I have a set of classes that use reflection and require the KClass object for the 'type' of the class - this is a GUI class that shows a list or edit form for a type. Rougly: class BaseView<T>( val kclass : KClass<T> ) { } class FormView : BaseView<AFormType>( AFormType::class ) { ... } I'd like to get rid of either the need for the constructor parameter and/or the need to explicitly pass it e.g. this would be nice class BaseView<T>( val kclass : KClasss<T> = T::class ) // inline constructor<reified T> ??? Is this possible ? I can make a function that does this but I cant derive from it -- (?) fun <reified T> BaseView() = BaseView<T>(T::class) --> but how to derive ? Any suggestions ?
    a
    s
    • 3
    • 11
Powered by Linen
Title
d

DALDEI

08/15/2020, 3:45 PM
'reified' constructor type parameters ? Possible ? I have a set of classes that use reflection and require the KClass object for the 'type' of the class - this is a GUI class that shows a list or edit form for a type. Rougly: class BaseView<T>( val kclass : KClass<T> ) { } class FormView : BaseView<AFormType>( AFormType::class ) { ... } I'd like to get rid of either the need for the constructor parameter and/or the need to explicitly pass it e.g. this would be nice class BaseView<T>( val kclass : KClasss<T> = T::class ) // inline constructor<reified T> ??? Is this possible ? I can make a function that does this but I cant derive from it -- (?) fun <reified T> BaseView() = BaseView<T>(T::class) --> but how to derive ? Any suggestions ?
a

Andrea Giuliano

08/15/2020, 3:46 PM
reified is not supported in constructors (yet)
d

DALDEI

08/15/2020, 3:48 PM
Yes. Is there an alternative way to achive something similar ?
a

Andrea Giuliano

08/15/2020, 3:48 PM
what you can do is, you can accept KClass (or java class) in the constructor
d

DALDEI

08/15/2020, 3:50 PM
Yes. Thats what Im doing. Would like to avoid that. A class delegate by function might work but its not the same and would require interfaces -- class View<T>: BaseView<T> by reifiedFunction<T>() { }
If that worked then so would a constructor default value by reified function
a

Andrea Giuliano

08/15/2020, 3:51 PM
the only thing you can do is create an extension function to achieve this. Something like
reified fun View()...
d

DALDEI

08/15/2020, 4:11 PM
This see3ms to work --
abstract class X<T:Any>() {
val x : Int = 1
abstract fun getView() : KClass<T>
}
inline fun <reified T:Any>  X<T>.view() = T::class
class Y : X<StatementJob>() {
override fun getView() = view()
}
Not exactly simplier -- but maybe a way to morph it into something
s

streetsofboston

08/15/2020, 4:19 PM
You can use smart-constructors:
class MyClass private constructor(...) {

    companion object {
        inline operator fun <reified T> invoke(...): MyClass {
        }
    }
}
Then you can construct it still like this
val mc = MyClass(…)
, because it is the same as
val mc = MyClass.invoke(…)
👍 3
d

DALDEI

08/16/2020, 12:38 PM
Yes. But that only works when the call is not the constructor itself. I.e. you cant derive from a class that requires the type parameter and a class instance in the constructor, So like my method, one has replace a bit of clumbsy boilerplate with a LOT of clumbsy boilerplate -- it didnt go away.
easier to make a global reified function of the same name -- for cases that you dont need it to be a 'constructor' literlly - just look like one in some cases.
View count: 3