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

    aerb

    12/29/2017, 10:41 PM
    Hey, is there a way to call an extension method with appropriate namespace, as you would with a static method? Basically to deal with name conflicts?
    d
    a
    • 3
    • 16
  • r

    redrield

    12/30/2017, 7:06 AM
    I've got a
    BehaviorSubject<Int?>
    , but IntelliJ is insisting that I have to pass an Int to onNext
    m
    a
    +2
    • 5
    • 6
  • g

    groostav

    12/31/2017, 6:51 AM
    hmm, through some serialization shenanigans, I've got an instance
    t
    of something thats declared as
    object  Thingy
    , that is not equal to
    Thingy.INSTANCE
    . I could update all my when statements to use
    when(it) { is Thingy ->
    rather than
    when(it) { Thingy ->
    , but that seems cryptic.
    a
    • 2
    • 1
  • g

    groostav

    12/31/2017, 6:52 AM
    but what I'd really like is to direct kotlin to just insert a
    readResolve
    method on all things declared as
    object
    .
    k
    • 2
    • 1
  • l

    looki

    12/31/2017, 10:43 AM
    Hi all, I'm having a hard time with gson because of it's use of Unsafe that leads to non-nullable variables getting null as value. Can somebody recommend me a JSON serializer library that works properly with Kotlin
    l
    • 2
    • 1
  • a

    andredasilvapinto

    12/31/2017, 7:01 PM
    Hello! This - https://gist.github.com/andredasilvapinto/a63468acd56498fd6f17bcad2905d41b - compiles but when I run it produces a
    java.lang.VerifyError: Bad type on operand stack
    (full error on the gist comment). Why is that?
    k
    • 2
    • 4
  • d

    dave08

    01/01/2018, 2:00 PM
    Out of the results of:
    "0101-1002-0909-0210-1115-1511".split("-")
                .flatMap { it.chunked(2).map { it.toInt() } }
            	.map { if (it > 9) (it + 55).toChar() else (it + 48).toChar() }
            	.chunked(2)
    I need:
    11:A2:99:2A:BF:FB
    , how could I do that idiomatically, also, is there a simpler algo for this? It's converting to hex..
    e
    k
    • 3
    • 6
  • b

    birgersp

    01/01/2018, 2:33 PM
    Hi all! I'm creating a web-application with Kotlin/JS. I want the generated .js files to be automatically copied into a directory whenever the modules successfully builds. Is there a clean and easy way? Couldn't find such a feature in IntelliJ, is it easier to create a bash script to copy the files whenever they change?
    g
    • 2
    • 16
  • v

    Viral

    01/02/2018, 5:17 AM
    do any one have pdf copy of kotlin in action ?
    r
    t
    • 3
    • 3
  • r

    robstoll

    01/02/2018, 12:08 PM
    Does someone know how I can bring nullable in the following parameter in terms of a type parameter
    class A<T>(val a: B<T>.()->Unit)
    I tried:
    class A<T1, T2: (B<T>.()->Unit)? >(val a: T2)
    But that failes stating that an extension function type cannot be used as upper bound. I want to be able to have the parameter nullable in some places and not nullable in others without creating two classes for it
    d
    • 2
    • 6
  • c

    claudiug

    01/02/2018, 12:47 PM
    hello guys, any one is using kotlin with a web framework beside spring?
    n
    i
    +2
    • 5
    • 4
  • p

    poohbar

    01/02/2018, 4:40 PM
    have you ever seen Kotlin code throw:
    java.lang.IncompatibleClassChangeError: Implementing class
    
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        ...
    a
    • 2
    • 1
  • n

    nicola.de.fiorenze

    01/02/2018, 5:03 PM
    Hi guys! I have something like this:
    interface Base {
        fun print()
    
        fun getValue() : String
    }
    
    class BaseImpl : Base {
    
        override fun print() { print(getValue()) }
    
        override fun getValue(): String {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
    }
    
    class Derived(private val b: Base) : Base by b {
        override fun getValue(): String = "hello"
    }
    
    fun main(args: Array<String>) {
        val b = BaseImpl()
        Derived(b).print() // prints 10
    }
    obviously the output is
    Exception in thread "main" kotlin.NotImplementedError: An operation is not implemented: not implemented
    	at BaseImpl.getValue(Main.kt:12)
    	at BaseImpl.print(Main.kt:9)
    	at Derived.print(Main.kt)
    	at Main3Kt.main(Main.kt:22)
    which is the cleanest way to refactor this snippet to specify in
    Derived
    what should be used in
    BaseImpl.print()
    ?
    a
    • 2
    • 3
  • p

    poohbar

    01/02/2018, 7:28 PM
    val f1 = { it.length == 3}   // T.() -> Boolean
    val f2 = { length == 3} .    // (T) -> Boolean
    this does not look the same to me
    a
    k
    +2
    • 5
    • 19
  • a

    adam-mcneilly

    01/03/2018, 12:38 AM
    Everyone else just replacing a single letter. Surprised it wasn't KSON for example.
    s
    • 2
    • 2
  • t

    tschuchort

    01/03/2018, 12:30 PM
    is there any way to get a hold of a
    Map
    entry without iterating over the whole entry set? I need it to be able to change the associated value of a key repeatedly without having to find the key in the map again every time.
    d
    m
    +3
    • 6
    • 14
  • k

    kassim

    01/03/2018, 1:32 PM
    I’m wondering. Kotlin doesn’t allow you to call methods with generics with specifying the type - which is one of the few situations where I’m forced to write more code than with Java. e.g.
    val example = listOf()
    won’t compile, I must write
    val example = listOf<Any>()
    see examples: https://kotlinlang.slack.com/archives/C0922A726/p1514989124000312?thread_ts=1514986352.000228&amp;cid=C0922A726 https://kotlinlang.slack.com/archives/C0922A726/p1514987282000262?thread_ts=1514986352.000228&amp;cid=C0922A726 Why is this forced? I’ve Googled but can’t find discussion on it
    l
    k
    +3
    • 6
    • 49
  • m

    Marc Reichelt

    01/03/2018, 4:22 PM
    Hi there! What is the best channel here to ask about building DSLs?
    a
    • 2
    • 2
  • t

    tschuchort

    01/03/2018, 5:40 PM
    is it possible to have generics that need to fulfill one upper bound or the other? With where clauses you can only specify multiple upper bounds that all need to be fulfilled at the same time
    a
    • 2
    • 2
  • p

    poohbar

    01/04/2018, 2:35 AM
    i get
    kotlin/reflect/jvm/internal/KotlinReflectionInternalError
    when running the app from jar, but the app works from intellij
    a
    • 2
    • 1
  • m

    Marcus Fihlon

    01/04/2018, 9:12 AM
    I thought that exceptions have to be thrown. In my case I have a test and when I create an exception it is thrown automatically and I don’t understand, why:
    class RuntimeExceptionMapperTest :  StringSpec() {
        init {
            val mapper = RuntimeExceptionMapper()
            "ConcurrentModificationException should be mapped to CONFLICT (409)" {
                val e = ConcurrentModificationException("Test") // throws exception - why?
                mapper.toResponse(e).status shouldBe CONFLICT.statusCode
            }
        }
    }
    I use Kotlin 1.2.10 with KotlinTest 2.0.7 and have no idea, why the exception is thrown. I just want to create an exception object, not throwing it…
    k
    • 2
    • 1
  • d

    damian

    01/04/2018, 11:33 AM
    is there a way i can use the
    class
    of my generic? my construct looks like this:
    abstract class Base<T: Parent> {
     val something: MyGenericClass<T>(T::class.java)
    }
    but it says i cant use
    T
    as reified type parameter and should use a class instead.
    s
    k
    • 3
    • 2
  • s

    snrostov

    01/04/2018, 12:19 PM
    Why in this code type
    GT
    cannot be inferred?
    class A<T>(val t: T)
    class B<T, out U: A<T>>(val t: T, val at: U)
    
    fun <T> B<T, *>.withCapturedU(): B<T, A<T>> = this
    
    private fun <FT> f(x: B<FT, *>) {
      g(x) // ERROR, why?
      g(x.withCapturedU()) // OK
    }
    
    private fun <GT>  g(y: B<GT, A<GT>>) {
      println(y)
    }
    a
    • 2
    • 5
  • c

    cedric

    01/04/2018, 7:57 PM
    This is obviously a regression (I filed a ticket but just curious if somebody else saw that too)
    k
    • 2
    • 2
  • j

    jw

    01/04/2018, 8:42 PM
    Gradle 4.4 or newer, sourceCompatibility = JavaVersion.VERSION_1_9; targetCompatibility = JavaVersion.VERSION_1_9
    i
    • 2
    • 1
  • d

    deviant

    01/04/2018, 10:07 PM
    guys, which one lib is more mature:
    exposed
    or
    squash
    ? it seems both serve for same purpose
    👍 1
    o
    • 2
    • 1
  • m

    molikto

    01/05/2018, 4:37 AM
    things I miss in Kotlin (compared to Scala): type members value types things I miss in Scala (compared in Kotlin): null operators and smart cast extension functions inline methods I wish the two language can be combined...
    m
    • 2
    • 1
  • p

    phantom

    01/05/2018, 10:30 AM
    does anyone actually use Kotlin DSL for HTML [https://github.com/Kotlin/kotlinx.html]
    g
    • 2
    • 1
  • m

    mwerschy

    01/05/2018, 4:28 PM
    Anyone know how to fix
    Cannot access 'clazz': it is private/*private to this*/ in 'Test'
    ?
    class Test<out T>(private val clazz: Class<@UnsafeVariance T>) {
        companion object {
            fun test(test: Test<*>) = test.clazz
        }
    }
    Making
    clazz
    public or making
    T
    invariant fixes the error but I'd prefer to avoid that. Companion objects should have access to private members so this should work as is.
    y
    • 2
    • 4
  • s

    Sam

    01/05/2018, 5:36 PM
    Is that conceptually a good use of a data class? I’ve written them with methods in them but typically limit the methods to adding extra meaning to the data like isExpired or fullName methods/properties.
    z
    y
    • 3
    • 2
Powered by Linen
Title
s

Sam

01/05/2018, 5:36 PM
Is that conceptually a good use of a data class? I’ve written them with methods in them but typically limit the methods to adding extra meaning to the data like isExpired or fullName methods/properties.
z

ziad

01/05/2018, 5:45 PM
Would you rather just expose the underlying data structure (so a public map in this case), and have consumers of the data class read it directly?
y

yole

01/05/2018, 5:57 PM
I wouldn’t. encapsulating the underlying data structure is always a good idea
View count: 1