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

    Adrian M

    04/11/2018, 12:55 PM
    Hey, should
    @BeforeAll
    annotated method from super class be executed before tests from child class?
    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
    open class TestBase {
    
        var status: Boolean = false
    
        @BeforeAll
        open fun setStatus() {
            status = true
        }
    }
    
    class MyAppTest : TestBase() {
    
        @test
        fun testStatus() {
            assertTrue(status) //fails
        }
    
    }
    s
    • 2
    • 3
  • n

    Nelson Plinio

    04/11/2018, 12:56 PM
    Good morning everyone, somebody know how create .jar from kotlin script and how executa in command line?
    h
    • 2
    • 1
  • a

    Andreas Sinz

    04/11/2018, 2:20 PM
    @Nelson Plinio a *.kts file or with kotlin gradle script?
    n
    • 2
    • 2
  • j

    Joel Armstrong

    04/11/2018, 5:35 PM
    Anyone know the best way to convert something like the following to Kotlin?
    public class PublicClassProtectedConstructor {
            protected PublicClassProtectedConstructor(params...)
    }
    
    public class Factory {
            public static PublicClassProtectedConstructor factoryMethod1(...) ...
    
            public static PublicClassProtectedConstructor factoryMethod2(...) ...
    }
  • j

    Joel Armstrong

    04/11/2018, 5:39 PM
    Essentially I just want a public class but with protected constructor (I understand this isn't possible in Kotlin) so that the only way to construct it is through the factory
    c
    f
    • 3
    • 9
  • j

    jasondlee

    04/11/2018, 7:52 PM
    basically, i'm trying to work up a novel dsls-in-kotlin presentation for my local JUG. current approach is a DSL describing a REST service. probably akin to ktor, but backed with, say, Jersey
    👍 1
    j
    • 2
    • 5
  • j

    jasondlee

    04/12/2018, 2:51 AM
    fwiw, here's what I've been tinkering on. one evening's worth of work, so it's nothing special, but it's a fun start: http://www.jasondl.ee/posts/2018/jerkey-a-kotlin-dsl-for-jersey.html
    j
    • 2
    • 2
  • a

    Andrzej Sawoniewicz

    04/12/2018, 9:52 AM
    I had some problems with Dagger2 Provider. In my test kotlin I want to construct an object with Provider<DateTime!>! type (it is defined as java code). I create a val today = dateTimeFormatter.parseDateTime("17-09-22") and I try to put an argument like { today } to the constructor. I get Type mismatch. Required: Provider<DateTime!>! Found: () -> DateTime! What is more strange I have exactly the same code in other test with similar object and it is working. What could be the problem?
    g
    • 2
    • 2
  • y

    Yuku Kotani

    04/12/2018, 10:45 AM
    Hi. Does anyone know how to cast generic type? I'm trying to make mapOf() returns EnumMap if K is Enum. An error occurs from this code.
    @kotlin.internal.InlineOnly
    public inline fun <reified K: Any, V> mapOf(): Map<K, V> =
        if (K::class.java.isEnum) EnumMap<K, V>(K::class.java)
        else emptyMap()
    Type argument is not within its bounds.
    Expected: Enum<K!>!
    Found: K
    k
    • 2
    • 17
  • j

    Jitesh Dedhiya

    04/12/2018, 10:51 AM
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
    d
    a
    • 3
    • 6
  • s

    Shawn

    04/12/2018, 3:13 PM
    we just lose access to older files
    ✅ 1
    c
    • 2
    • 2
  • m

    mbickel

    04/12/2018, 3:33 PM
    Do I file this as a Intellij Debugger or as a Kotlin issue?
    d
    • 2
    • 1
  • r

    Ruckus

    04/12/2018, 8:07 PM
    There isn't really partial application in Kotlin, you just wrap it with another function.
    val add: (Int, Int) -> Int = { a, b -> a + b }
    val add5: (Int) -> Int = { add(it, 5) }
    assert(add5(10) == 15)
    r
    • 2
    • 3
  • m

    MattIPv4

    04/13/2018, 9:46 AM
    Hey everyone, sorry to interupt. We now have a JetBrains (unofficial) discord server if you'd like to join and hang out with loads of JetBrains users and staff. We have channels for every JetBrains product including Kotlin 🙂 https://discord.gg/ysd6M4r
    s
    w
    o
    • 4
    • 7
  • r

    rmarinsky

    04/13/2018, 10:35 AM
    Hi guys, anybody know hot to run Runnable class at the current thread?
    l
    k
    g
    • 4
    • 6
  • d

    dierre

    04/13/2018, 2:18 PM
    Hello, I have an interoperability design issue that you can help me with. I’m really fond of kotlin DSL so I did something like this:
    class Car (
            val model: String?,
            val year: Int,
            val required: String
    ) {
    
        private constructor(builder: Builder) : this(builder.model, builder.year, builder.required)
    
        companion object {
            inline fun build(required: String, block: Builder.() -> Unit) = Builder(required).apply(block).build()
        }
    
        class Builder(
                val required: String
        ) {
            var model: String? = null
            var year: Int = 0
    
            fun build() = Car(this)
        }
    }
    so that in kotlin I can do
    val car = Car.build(required = "") {
            model = "X"
            year = 120
        }
    The problem is that in Java then I need to write:
    Car.Builder builder = new Car.Builder("required");
            builder.setModel("X");
            builder.build();
    to do the same stuff. This is not really readable. So I did something this:
    class CarJavaFriendly(private val model: String?, private val year: Int) {
        
        private lateinit var required: String
        
        fun withRequired(b: String) = this.apply { required = b }
    
        fun execute() {
            tryExecute { someFunction() } }
        }
    
        private fun <B> tryExecute(f: () -> B): B = try {
            f()
        } catch (e: UninitializedPropertyAccessException) {
            val msg = e.message?.replace("lateinit property ", "") ?: "a property has not been initialized"
            throw ValueRequiredException(msg)
        }
    }
    so that in java you can write
    CarJavaFriendly carJavaFriendly =
                    new CarJavaFriendly("X", 1)
                            .withRequired("x")
                            .execute(somefunction());
    so that I can exploit lateInit to check if a parameter which is required, it’s actually initialized. Do you think is there a better approach when it comes to writing API which are readable for Java as well?
    k
    • 2
    • 1
  • v

    v79

    04/13/2018, 4:23 PM
    What's preferred in Kotlin - casting or reified Generics? I'm using reflection to build arbitrary objects given some values in a
    request
    (from Spark-Kotlin). It started with
    val person = Form(request,Person::class).get() as Person
    . Then i created an extension function
    val person = request.bind(Person::class) as Person
    . Latest version uses reified generics
    val person = request.bind<Person>()
    . Are there any clear problems using the reified generic extension function approach?
    g
    c
    • 3
    • 2
  • v

    visakha

    04/13/2018, 5:12 PM
    Is there a Spring-Kotlin channel
    f
    • 2
    • 2
  • r

    Ruckus

    04/13/2018, 5:25 PM
    This won't work if you're in the global package, but let's be honest, you shouldn't be. 🙂
    🙃 1
    s
    • 2
    • 6
  • n

    nfrankel

    04/14/2018, 7:24 AM
    hi guys i’ve just noticed that functions declared inside functions cannot be used before they have been declared 🤔 so i get this kind of sequence:
    fun main(args: Array<String>) {
    
        val client = Client("url", "key", "secret")
    
        fun Command.execute() = client.execute(this).third.fold({ println(it) }, { throw it })
    
        ListVolume().execute()
        ListFirewallRules().execute()
    }
    i would like to have it at the end, as an implementation detail anyone can confirm? and tell me whether i can do it otherwise to make it more readable also, i would be interested in the reason and if it might change in the future
  • m

    Marcel Overdijk

    04/14/2018, 11:37 AM
    I have to explicitly use the
    !!
    operator here. I wonder if there is bettter, idiomatic way to do this with Kotlin?
    c
    • 2
    • 2
  • b

    BRIAN256

    04/14/2018, 3:39 PM
    Hey guys any kotlin speaker here
    🤔 4
    🙋‍♂️ 2
    n
    p
    • 3
    • 3
  • g

    groostav

    04/14/2018, 5:02 PM
    Does anybody here use semantic merge (https://www.semanticmerge.com/)? I think its a really neat idea, though its effectively a language-specific merge tool. They support some of the bigger langauges, but their support claims that theyre front-end is fairly pluggable, meaning theres a fairly simple API to get it to work with other languages (IE kotlin), has anybody done this/would want to do this?
    • 1
    • 1
  • m

    mplacona

    04/14/2018, 9:08 PM
    Does anyone know of a solution to run Kotlin source code at runtime? Found this post from 2015, but wondering if there's been any updates from then. https://discuss.kotlinlang.org/t/loading-source-at-runtime/58
    c
    • 2
    • 5
  • e

    egordeev1

    04/15/2018, 12:01 PM
    Hello, please, explain why autocasting not working. i have the code: if (fragment is SearchFragment?) { (fragment as SearchFragment?)?.setOnlineNumber(online_number) } but if i write: if (fragment is SearchFragment?) { (fragment)?.setOnlineNumber(online_number) } it tells me "Unresolved reference: setOnlineNumber"
    a
    c
    +2
    • 5
    • 9
  • g

    goto1134

    04/15/2018, 1:29 PM
    Hello. How can I get KType of a nullable variable?
    c
    • 2
    • 3
  • y

    ylemoigne

    04/15/2018, 7:57 PM
    I have a
    java.lang.IllegalAccessError: tried to access field  ....
    at runtime, all is green in the idea. (using kotlin 1.2.31). Should I fill an issue ?
    e
    s
    • 3
    • 9
  • b

    brescia123

    04/16/2018, 8:26 AM
    Hi @ilya.gorbunov @orangy, I was reasoning about the semantic meanining of the stdlib’s
    public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean
    with my colleagues and I realized that a lot of them have different intuitive expectations about the output of the function when called on an empty list. Can you provide some insights about the decision of make it return
    true
    if the list is empty? Thanks!
    o
    e
    +3
    • 6
    • 11
  • h

    hhariri

    04/16/2018, 9:55 AM
    Friendly reminder - we do not allow integrations with third-party apps on this Slack.
    ❓ 1
    👍 2
    • 1
    • 1
  • s

    stephanc

    04/16/2018, 12:02 PM
    Whoop, Kotlin books in today's deal of the day on https://www.manning.com/dotd , 50% off Kotlin in Action and The Joy of Kotlin (MEAP) Don't know if I'm allowed to post this here, but thought it might benefit some. I'm not affiliated with Manning in any way 😉
    🤓 1
    👍 2
    s
    w
    • 3
    • 6
Powered by Linen
Title
s

stephanc

04/16/2018, 12:02 PM
Whoop, Kotlin books in today's deal of the day on https://www.manning.com/dotd , 50% off Kotlin in Action and The Joy of Kotlin (MEAP) Don't know if I'm allowed to post this here, but thought it might benefit some. I'm not affiliated with Manning in any way 😉
🤓 1
👍 2
s

stan0

04/16/2018, 12:37 PM
First time buying from that site - it asks me to login after buying the book as a guest 😄 And it’s supposed to be a “one-time download link”. Hope they fix it soon
s

stephanc

04/16/2018, 12:45 PM
Weird, I have an account, so don't know about the Guest checkout, there are some benefits for having an account, like livebook and discussion forums (in the case of buying a MEAP)
w

waqas

04/16/2018, 4:33 PM
@stephanc What do u think about The Joy of Kotlin, do u recommend?
s

stephanc

04/17/2018, 7:21 AM
@waqas Sorry for only getting back to you now. I only had a quick look through the first part of the book, and it looked interesting, so I bought it because I already had a copy of Kotlin in Action. 😄 Sorry can't say more. But you can look at the free chapter and the titles of the other chapters, to see if this is going to be something worthwhile for you.
w

waqas

04/17/2018, 8:51 AM
@stephanc no problem, I did go through first chapters and looked interesting, bought it! 😒imple_smile:
s

stephanc

04/17/2018, 8:52 AM
@waqas awesomeness 😃
View count: 3