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

    Marcus Fihlon

    03/19/2017, 9:51 AM
    Well, and I don’t understand Slack formatting, too… 😉
    d
    • 2
    • 1
  • m

    miha-x64

    03/19/2017, 10:37 PM
    I'm kinda stuck when the compiler said that this function:
    fun a(items: Array<Item>)
    cannot be invoked like this:
    fun b(vararg items: Item) {
        a(items)
    }
    because...
    items
    is
    Array<out Item>
    , not
    Array<Item>
    . This also means that I can't write to this array. Why? This may lead to situations when some code cannot be converted from Java.
    m
    m
    • 3
    • 2
  • a

    athor

    03/20/2017, 12:45 AM
    whats the correct way to pass ‘this’ to a property in a constructor?
    a
    • 2
    • 1
  • k

    krissrex

    03/20/2017, 1:48 PM
    Hi, any clue why my main function no longer works after updating to 1.1.1? Using Idea and gradle. Trying to run main from the IDE spits out this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
    	at com.mypackage.something.MainKt.main(Main.kt)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
    Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	... 6 more
    Looks like it struggles with the runtime or stdlib, but I'm not sure. It worked before, and I have applied kotlin as a gradle plugin, and the stdlib is in my dependencies.
  • s

    sannysanoff

    03/20/2017, 11:17 PM
    strange, lots of extension methods on String, like toShortOrNull... I would like to have str.toNotEmptyOrNull()?:"replacement" but shorter
    k
    • 2
    • 1
  • b

    benleggiero

    03/21/2017, 3:47 PM
    In fact, the opposite. I'm trying to have a really strong reason to always have them match. So, when I distribute a JAR for 64-bit machines, I want all integers and fractions to be 64-bit. On the other hand, when I distribute the 32-bit, I want all integers and fractions to be 32-bit. I don't like this mixed approach.
    d
    m
    • 3
    • 9
  • b

    boombastech

    03/21/2017, 4:13 PM
    Hi, I'm playing around with Kotlin and am using Gson too. I'm trying to use Gson to convert an object that has a reference to a property with type KClass. Gson throws a Stackoverflow exception for this, does anyone have an idea why please?
    m
    • 2
    • 8
  • e

    elezium

    03/25/2017, 12:11 AM
    Ok. So it's just a matter of personal preference. Thanks,
    n
    • 2
    • 2
  • b

    benleggiero

    03/25/2017, 2:55 AM
    Why won't this compile?
    fun String.differingCharacters(other: String): List<Char> {
        var endList: MutableList<Char> = mutableListOf()
        (0..min(this.length, other.length)).forEach { index ->
            val thisChar = this[index]
            val otherChar = other[index]
            if (thisChar != otherChar) {
                endList += thisChar
            }
        }
        if (this.length < other.length) {
            endList += other.substring(this.length).toCharArray().asList()
        } else if (other.length > this.length) {
            endList += other.substring(this.length).toCharArray().asList()
        }
        return endList
    }
    Errors:
    Error:(123, 21) Kotlin: Assignment operators ambiguity:
    public operator fun <T> Collection<Char>.plus(element: Char): List<Char> defined in kotlin.collections
    @InlineOnly public operator inline fun <T> MutableCollection<in Char>.plusAssign(element: Char): Unit defined in kotlin.collections
    Error:(127, 17) Kotlin: Assignment operators ambiguity:
    public operator fun <T> Collection<Char>.plus(elements: Iterable<Char>): List<Char> defined in kotlin.collections
    @InlineOnly public operator inline fun <T> MutableCollection<in Char>.plusAssign(elements: Iterable<Char>): Unit defined in kotlin.collections
    Error:(129, 17) Kotlin: Assignment operators ambiguity:
    public operator fun <T> Collection<Char>.plus(elements: Iterable<Char>): List<Char> defined in kotlin.collections
    @InlineOnly public operator inline fun <T> MutableCollection<in Char>.plusAssign(elements: Iterable<Char>): Unit defined in kotlin.collections
    i
    • 2
    • 3
  • d

    darkmoon_uk

    03/25/2017, 4:18 AM
    I’ve noticed @Throws annotation being added to some auto-translated Java -> Kotlin code. Given that Kotlin does not use checked exceptions, is this annotation optional; i.e. only required if I need exception inter-op with Java code?
    b
    • 2
    • 3
  • a

    Andreas Sinz

    03/25/2017, 3:30 PM
    @ra1nmak3r different standard library from java
    i
    • 2
    • 1
  • b

    benleggiero

    03/26/2017, 9:14 PM
    Why do I get this error?
    java.lang.VerifyError: Bad type on operand stack
    Exception Details:
      Location:
        org/bh/tools/base/strings/TestUtils.concat(Ljava/lang/Object;Ljava/lang/CharSequence;)Ljava/lang/CharSequence; @28: invokevirtual
      Reason:
        Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'java/lang/String'
      Current Frame:
        bci: @28
        flags: { }
        locals: { 'java/lang/Object', 'java/lang/CharSequence' }
        stack: { 'java/lang/StringBuilder', 'java/lang/Object' }
      Bytecode:
        0x0000000: 2a12 59b8 0012 2b12 43b8 0012 2ac1 005b
        0x0000010: 9900 1a2a bb00 1659 b700 1a5f b600 512b
        0x0000020: b600 5eb6 0052 c000 23b0 2ac1 0016 9900
        0x0000030: 152a c000 162b b600 5e59 1260 b800 63c0
        0x0000040: 0023 b0bb 0016 59b7 001a 2ab6 0047 2bb6
        0x0000050: 005e 5912 65b8 0063 c000 23b0          
      Stackmap Table:
        same_frame(@42)
        same_frame(@67)
    
    
    	at org.bh.tools.base.math.NumberConversionKtTestKt.assertNumbersClose(NumberConversionKtTest.kt:488)
    	at org.bh.tools.base.math.NumberConversionKtTest.Number_float32Value(NumberConversionKtTest.kt:47)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runners.Suite.runChild(Suite.java:128)
    	at org.junit.runners.Suite.runChild(Suite.java:27)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:58)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    At this line: https://github.com/BlueHuskyStudios/Blue-Base/blob/dev/JVM/test/org/bh/tools/base/math/NumberConversionKtTest.kt#L47
    r
    • 2
    • 4
  • s

    squeezymo

    03/27/2017, 1:56 PM
    Hi there! Am I right in assuming it’s not possible to declare a custom setter for a field initialized in the primary constructor?
    o
    m
    v
    • 4
    • 4
  • b

    benleggiero

    03/28/2017, 12:33 AM
    Anyone else have any ideas?
    e
    • 2
    • 3
  • e

    elect

    03/30/2017, 1:45 PM
    tried
    infix fun (() -> Unit).shallThrow(java: Class<*>)
    but it doesn't work
    m
    • 2
    • 2
  • a

    aphex

    03/30/2017, 1:45 PM
    fun fromActivity(activity: Activity?): Source = when {
                    activity != null && activity is FooActivity -> Source.FOO
                    else -> Source.UNKNOWN
                }
    Something tells me I don’t need the null check in the above code. Can I get rid of it and have the same exact behavior?
    r
    • 2
    • 8
  • k

    krissrex

    04/01/2017, 3:53 PM
    Does kotlin have any classes for observable lists? Kind of like
    Delegates.observable
    , but for
    add
    and
    remove
    v
    • 2
    • 3
  • r

    ralf

    04/04/2017, 5:35 PM
    I have no experience with the JavaScript interoperability. So can somebody confirm that you can call Kotlin code from JavaScript and vice versa like it works with Java and Kotlin?
    b
    • 2
    • 2
  • n

    nikolaymetchev

    04/06/2017, 11:50 AM
    cool. Is this preferable?
    fun sql(colb : Int?) = "SELECT * FROM TABLE WHERE A=3 ${colb?.let {" AND B=$it"}.orEmpty()}"
    v
    • 2
    • 7
  • e

    elect

    04/08/2017, 12:53 PM
    I'd like to check if a
    lateinit
    has been initialized, according to https://youtrack.jetbrains.com/issue/KT-9327#comment=27-1845509 there should be a
    javaField
    but I have nothing like that
    m
    • 2
    • 2
  • e

    equeim

    04/08/2017, 7:29 PM
    @Andreas Sinz Yes, IDEA 2017.1
    a
    • 2
    • 2
  • w

    waltaro

    04/09/2017, 1:14 AM
    Is anybody available to give me a bit of a hand?
  • e

    elect

    04/09/2017, 7:01 AM
    is it possible to have
    inline fun <T, R> binding(pair: Pair<Int, Int>, block: T.() -> R) {
    where
    T
    is decided based on
    pair.second
    ?
    u
    • 2
    • 5
  • m

    miha-x64

    04/10/2017, 7:34 PM
    You're right, subject expression is inaccessible in
    when
    . This feature is being discussed.
    e
    • 2
    • 3
  • r

    roberto.guerra

    04/11/2017, 4:55 PM
    I’ve encountered other similar issues where the only way around it was having a
    /src/main/java
    and a
    /src/main/kotlin
    . So now I just default to that to save me hours of troubleshooting in the future.
    v
    • 2
    • 1
  • w

    wfisher

    04/13/2017, 7:14 PM
    Is there a good way to deal with data classes and inheritance? Is the best way to do this to make the Parent's
    a
    open and the Childrens'
    a
    override? I'd really just like for the
    a
    of the children not to be a
    val
    .
    sealed class Parent(val a: Int)
    data class Child1(val a: Int, val b: Int) : Parent(a)
    data class Child2(val a: Int, val c: Int): Parent(a)
    a
    • 2
    • 1
  • c

    czyzby

    04/14/2017, 9:22 PM
    This is my use case: https://github.com/czyzby/ktx/blob/master/style/src/main/kotlin/ktx/style/style.kt I'd like to prohibit users from using the API like this:
    skin {
      label {
        label { // Should not compile: not a direct child of skin.
        }
      }
    }
    e
    • 2
    • 3
  • i

    ilya.gorbunov

    04/15/2017, 4:36 AM
    If you do not control types used in your dsl, you can apply dsl annotation to the receiver type of function-with-receiver parameter, something like this:
    fun skin(init: (@MyStyleDsl Skin).() -> Unit): Skin
    where
    MyStyleDsl
    is an annotation, annotated with
    @DslMarker
    👍 3
    c
    • 2
    • 1
  • s

    sannysanoff

    04/17/2017, 9:26 AM
    Hi, is it supposed to work? named@for() { synchronized(obj) { ... continue@named; } } ? I was under impression that synchronized is inline function, and therefore there's no restrictions on control flow statements inside passed lambda, but compiler gives an error.
    e
    s
    • 3
    • 5
  • n

    nawar

    04/17/2017, 11:18 AM
    I’m trying to get some thoughts on which library/framework to use, in my next Android project, for HTTP and image download and plays well with Kotlin.
    m
    • 2
    • 5
Powered by Linen
Title
n

nawar

04/17/2017, 11:18 AM
I’m trying to get some thoughts on which library/framework to use, in my next Android project, for HTTP and image download and plays well with Kotlin.
m

miha-x64

04/17/2017, 11:22 AM
OkHttp is standard in HTTP, Retrofit — in REST. For image downloading I prefer Picasso, but many people use Glide.
n

nawar

04/17/2017, 11:31 AM
So, you’d use all those in conjunction. Great to know.
m

miha-x64

04/17/2017, 11:48 AM
Yes, Retrofit depends on OkHttp, and Picasso has an option to use OkHttp (OkHttp3Downloader). So, they can use the same cache and thread pool.
n

nawar

04/17/2017, 12:17 PM
Thanks for the tips Mike 🙂
Not just quite used to the Android ecosystem coming from an iOS background where I handle most of the networking with
dataTask
🙂
View count: 1