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

    felipepedroso

    05/29/2019, 10:58 AM
    Is there a way to add a line break when using backticks to name a method? I'm in the middle of a huge refactoring and would like to write a good description on the tests that I'm creating for that. The long names will be gone later with the methods refactoring but it would be nice to have long names for now...
    t
    r
    +1
    6 replies · 4 participants
  • m

    Mahdi Javaheri

    05/29/2019, 12:27 PM
    Hi is there a way to tell kotlin that all of the functions inside an object or companion object must be annotated with
    @JvmStatic
    ? without need to annotating individual functions
    s
    a
    3 replies · 3 participants
  • t

    thana

    05/29/2019, 4:24 PM
    According to https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/synchronized.html
    synchronized
    for
    common
    but not for
    js
    and
    jvm
    - which in fact are the both platforms i target. is there a way to use it in
    common
    without the deprecation warnuing?
    e
    3 replies · 2 participants
  • k

    Kotlin-Jobs.com

    05/29/2019, 6:00 PM
    Hi folks - I created a new website to help with finding and posting jobs pertaining to Kotlin only and wanted to share it here. We also have an email subscription list you can subscribe to in order to get a weekly update of newly added jobs. Hope it helps some people out! You can visit it at https://kotlin-jobs.com/
    k
    1 reply · 2 participants
  • d

    Dan T

    05/29/2019, 8:25 PM
    Question on combining sealed classes with data classes, in thread.
    k
    s
    +3
    31 replies · 6 participants
  • k

    Kroppeb

    05/29/2019, 10:57 PM
    I have an issue with the following piece of code:
    inline fun StringReader.tryTo(block: StringReader.TryTo.() -> Unit){
    	contract {
    		callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
    	}
    	try {
    		it.block()
    	} catch (e: Exception) {
    		it.reset()
    	}
    }
    And
    override fun parse(reader: StringReader): String? {
    	reader.tryTo {
    		throw Exception("hi")
    	}
    	return null // Marked as unreachable code
    }
    On a inline lambda seems to not realise that an exception that is thrown in the lambda can be caught in the inlined function. This gets even worse when the return is not nullable and the user doesn't add a return as it is marked as unreachable and as a result at runtime the function will return null.
    k
    12 replies · 2 participants
  • v

    Valentyn

    05/30/2019, 12:59 AM
    Hey community, I am looking for example gradle script to build and publish jar + doc to the maven central repository. Please help.
    1 reply · 1 participant
  • m

    mike_shysh

    05/30/2019, 7:18 AM
    Hi, I need to add file on the fly (generate file). What is the most reliable way to do so? I think that generating file to /*out*/test/resources is not a good idea, isn't it?
    g
    b
    22 replies · 3 participants
  • r

    Rohan Maity

    05/30/2019, 9:49 AM
    @jonnyzzz could I DM you ?
    j
    1 reply · 2 participants
  • r

    Rak

    05/30/2019, 2:31 PM
    I don't understand the use of "*" in this context
    s
    k
    4 replies · 3 participants
  • m

    Marc Knaup

    05/30/2019, 3:06 PM
    Why is it
    *
    btw? Could be something more comprehensible like this 🤔
    ByteString.of(vararg buffer.toByteArray())
    s
    j
    +5
    61 replies · 8 participants
  • k

    Kroppeb

    05/30/2019, 8:10 PM
    Why does
    as? TArgument
    give an
    Unchecked cast
    warning
    s
    k
    +2
    28 replies · 5 participants
  • o

    oscarg798

    05/30/2019, 8:54 PM
    Hi guys one question, I want to have a variable that represent Any function. meaning that function can have from 0 to N different params, is that possible?
    r
    c
    13 replies · 3 participants
  • a

    andre.ramaciotti

    05/31/2019, 12:22 PM
    Is there a way of avoiding having to specify the same class twice in the code below? I have a generic abstract class, and I need to know what's the actual type (because I want to use it when deserializing with Jackson's
    ObjectMapper
    ). So I know that I need to pass the class as an argument. But then, I also need to specify the type
    T
    when instantiating the generic base class. Is there a way of making the compiler infer any of the two?
    data class ExamplePayload(val value: String, val otherValue: Int)
    
    abstract class Worker<T : Any>(private val kclass: KClass<T>) {
        private lateinit var objectMapper: ObjectMapper
    
        fun handleMessage(message: String) {
            val payload = objectMapper.readValue(message, kclass.java)
            work(payload)
        }
    
        protected abstract fun work(payload: T)
    }
    
    // Here I need to specify ExamplePayload twice:
    class ExampleWorker : Worker<ExamplePayload>(ExamplePayload::class) {
        override fun work(payload: ExamplePayload) {
            TODO("not implemented")
        }
    }
    l
    s
    +1
    9 replies · 4 participants
  • k

    Kroppeb

    05/31/2019, 3:34 PM
    Why is can't it figure out the type? I would assume it is quite clear, no?
    g
    k
    8 replies · 3 participants
  • q

    Quy D X Nguyen

    05/31/2019, 7:57 PM
    Is there a way to change the name of the variable that holds kotlin objects?
    g
    s
    3 replies · 3 participants
  • k

    karelpeeters

    06/01/2019, 12:00 AM
    Wait you're not actually stuck, looks like there's a solution targeted for 1.4: https://youtrack.jetbrains.com/issue/KT-11129
    e
    a
    3 replies · 3 participants
  • e

    enighma

    06/01/2019, 12:02 AM
    That's promising. I'm guessing we're still using 1.3 though, but good to know it's on the horizon.
    l
    3 replies · 2 participants
  • s

    SOFe

    06/01/2019, 7:13 AM
    There should be no ambiguity
    k
    7 replies · 2 participants
  • t

    thana

    06/01/2019, 11:04 AM
    you can only seperate declaration and initilization if the latter happens in a constructor or
    init
    block. in the end they wont be split this way. you can use
    by lazy{}
    with `val`s
    v
    p
    +1
    5 replies · 4 participants
  • a

    Andrew Gazelka

    06/02/2019, 1:54 AM
    wait why is this?
    g
    8 replies · 2 participants
  • a

    Andrew Gazelka

    06/02/2019, 2:13 AM
    also kinda seems weird to me that you can have multiple
    main
    functions in different files but not the same actual function name
    🤔 1
    g
    4 replies · 2 participants
  • a

    Andrew Gazelka

    06/02/2019, 2:18 AM
    also any reason why flows don't have an
    iterator()
    method?
    g
    1 reply · 2 participants
  • a

    Andrew Gazelka

    06/02/2019, 5:33 AM
    is there something like a channel but which can have two receivers?
    g
    24 replies · 2 participants
  • c

    cypher121

    06/02/2019, 8:33 AM
    I have a somewhat weird question. say I have following:
    fun <E : Enum<E>> foo(clazz: Class<E>): Value<E> = TODO()
    
    fun <T> bar(clazz: Class<T>) {
        if (Enum::class.java.isAssignableFrom(clazz)) {
            foo(clazz) //fails since T is not Enum<T>
        }
    }
    how do I call foo here? I tried
    foo<Enum<*>>(clazz as Class<Enum<*>>)
    but it fails since * is also not Enum<*> and it just keeps going recursively. In java I'd just use a raw Enum type, but I can't do that here
    d
    m
    +2
    15 replies · 5 participants
  • f

    Felix Novovic

    06/02/2019, 12:34 PM
    Hello! I don't know if this is the place to ask, but I was wondering if there is any way to print the output of a kts scratch file to the console or to somewhere I can copy it. I'm using the classpath of a project I'm working on and the script has external dependencies (cannot be run independently). This is how it looks like:
    val now = DateTime(DateTimeZone.UTC)
    val inTwoHours = now + Duration.standardHours(2)
    println(inTwoHours.millis)
    Very simple, I just want to copy the time in millis and put it in another file I'm messing around with. However, when I run the scratch file it evaluates perfectly fine but shows the output to the right of the
    println
    statement which I cannot copy or select. I really like the ideas of scratch files and I believe it to be an invaluable tool when doing some manual testing and experimentation but I cannot seem to find how to just print it to the normal console. Anyone has any clue? (Using IntelliJ Ultimate)
    t
    n
    5 replies · 3 participants
  • u

    uli

    06/02/2019, 1:06 PM
    Hi all, i get an unchecked cast warning on this code:
    typealias Factory<T> = () -> T
    
        private fun Bundle.getViewModelFactory(): (() -> VIEWMODEL)? {
            val serializable = getSerializable(ARG_VIEWMODEL_FACTORY)
            return serializable as? Factory<VIEWMODEL>
        }
    Shouldn't
    as?
    take care of this?
    c
    d
    +1
    8 replies · 4 participants
  • a

    AnnoymousGiraf

    06/02/2019, 11:44 PM
    Not sure where to pop this question, either Kotlin or Kotlin Native, does someone have experience with GO integration in Kotlin?
    g
    b
    12 replies · 3 participants
  • t

    thana

    06/03/2019, 8:59 AM
    data classes
    are not allowed to have non-properties in their primary constructors. otoh this means data classes cannot inherit from classes that require arguments in their own primary constructor. is there a way to overcome this issue? is this really intended? why?
    g
    p
    30 replies · 3 participants
  • t

    tseisel

    06/03/2019, 9:36 AM
    Why is the
    crossinline
    keyword required ? Is it a real language feature, or rather a technical limitation of the compiler ?
    g
    d
    3 replies · 3 participants
Powered by Linen
Title
t

tseisel

06/03/2019, 9:36 AM
Why is the
crossinline
keyword required ? Is it a real language feature, or rather a technical limitation of the compiler ?
g

gildor

06/03/2019, 9:38 AM
it’s to be explicit, that this lambda cannot be inlined by itself (in most cases because you pass it to some other non-online function)
👍 1
without this it may case cases when you think that lambda is inlined (because function is), but it’s not true, because instance still required
d

Dico

06/03/2019, 10:03 AM
It is also used to indicate that returns from the lambda will be invalid
👍 1
View count: 2