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

    Florian Wiesner

    03/07/2018, 4:29 PM
    When writing a gradle plugin in Kotlin, is there some hidden magic required to make properties of the extension class visible to Kotlin DSL?
    • 1
    • 1
  • a

    araqnid

    03/07/2018, 4:51 PM
    you need to refer to extension classes/convention classes more explicitly in Kotlin DSL, they don't magically appear as extension properties on the project
    f
    c
    m
    • 4
    • 85
  • d

    droidrcc

    03/07/2018, 5:17 PM
    how do you suggest to convert this
    while ((len = def.deflate(buf, 0, buf.size)) > 0) {}
    ?
    a
    • 2
    • 1
  • k

    kevinmost

    03/07/2018, 6:25 PM
    I know people are really split on them but even in Java, I personally prefer
    while (true)
    with a
    break
    over crazy assignments in the
    while
    condition:
    var len: Int = 0
    while (true) {
      len = def.deflate(buf, 0, buf.size)
      if (len <= 0) break
      ...
    }
    a
    c
    +4
    • 7
    • 25
  • w

    warriorprincess

    03/07/2018, 7:20 PM
    Got it. I was a little confused on how they differ
    c
    • 2
    • 3
  • d

    digitalsanctum

    03/07/2018, 7:43 PM
    Hi, anyone have a suggestion for something like copyRecursively which also supports retaining permissions? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/copy-recursively.html
    d
    • 2
    • 2
  • d

    dumptruckman

    03/08/2018, 2:04 AM
    since the tests are considered a separate module
    i
    • 2
    • 1
  • d

    dumptruckman

    03/08/2018, 2:21 AM
    anyway, there's no reason why internal and package-private can't coexist
  • l

    lovis

    03/08/2018, 6:51 AM
    Should we also rename
    flatten
    to
    smoosh
    ?
    :trollface: 2
    • 1
    • 1
  • c

    chan

    03/08/2018, 9:11 AM
    inline fun <reified T : Enum<T>> List<String>.toEnums(): List<T> {
      return this.map {
        enumValueOf<T>(it)
      }
    }
    a
    • 2
    • 3
  • k

    karelpeeters

    03/08/2018, 9:15 AM
    inline fun <reified T : Enum<T>> List<String>.toEnums() = map { enumValueOf<T>(it) }
    c
    • 2
    • 2
  • l

    Leonid

    03/08/2018, 9:20 AM
    Hi! Is it possible to declare a function type in Kotlin and have it implement a marker Interface?
    c
    d
    • 3
    • 10
  • a

    alex

    03/08/2018, 1:00 PM
    Are the both HTTP call implementation semantically identical, i.e. are both performing an async fetch? https://github.com/JetBrains/kotlinconf-app/blob/master/web/src/main/kotlin/org/jetbrains/kotlinconf/api/ajaxUtil.kt (1) implementation is an async fetch according to Kontlin's semantics? (2) implementation is an async fetch implemented with JavaScript semantics? Is my understanding correct? @orangy
    o
    • 2
    • 3
  • m

    m

    03/08/2018, 5:12 PM
    and output was of no use.
    c
    l
    • 3
    • 4
  • d

    Devon Humes

    03/08/2018, 8:58 PM
    Does anyone know why this code doesn’t work? I’m getting errors saying that the when is not exhaustive and that the return types don’t match.
    sealed class Parent {
        class Child : Parent()
    }
    
    interface Factory<T : Parent>
    
    class FactoryBuilder {
        fun <T : Parent> build(item: T): Factory<T> {
            return when(item) {
                is Parent.Child -> {
                    object : Factory<Parent.Child> {
    
                    }
                }
            }
        }
    }
    a
    o
    • 3
    • 34
  • k

    kristofdho

    03/09/2018, 12:16 AM
    also don't know how nice jaxrs plays with kotlin
    c
    • 2
    • 1
  • d

    dumptruckman

    03/09/2018, 3:09 AM
    I just suddenly started getting this error when compiling
    Error:(6, 47) java: cannot access xyz.jeremydwood.school.compiler.grammar.GrammarResult
      bad class file: D:\Users\Jeremy\Projects\tiny-compiler\out\production\classes\xyz\jeremydwood\school\compiler\grammar\GrammarResult.class
        class file contains malformed variable arity method: GrammarResult(xyz.jeremydwood.school.compiler.grammar.GrammarError,xyz.jeremydwood.school.compiler.grammar.GrammarResult[],kotlin.jvm.internal.DefaultConstructorMarker)
        Please remove or make sure it appears in the correct subdirectory of the classpath.
    s
    • 2
    • 3
  • r

    Rich Gabrielli

    03/09/2018, 1:16 PM
    I am looking to integrate a form into my app that requires hand written notes and digital handwritten signatures. I have come across PSPDFKit and it looks very promising. Does anyone have any experience? Thoughts? Alternatives?
    :stackoverflow: 3
    c
    • 2
    • 4
  • a

    Andreas Sinz

    03/09/2018, 3:01 PM
    @diesieben07 maybe when inline classes hit
    d
    • 2
    • 3
  • c

    christopher

    03/09/2018, 3:32 PM
    class Bar<T> protected constructor(type: Class<T>) {
        companion object {
            inline operator fun <reified T> invoke(): Bar<T> {
                return Bar(T::class.java)
            }
        }
    }
    
    val bar = Bar<String>()
    d
    • 2
    • 21
  • r

    Ruckus

    03/09/2018, 4:19 PM
    In my somewhat arrogant opinion, if you're navigating based on file name, you need a better IDE 🙂
    o
    j
    • 3
    • 4
  • c

    Czar

    03/09/2018, 4:39 PM
    Strictly on the topic though, such files are mostly collections of utility extensions, so I tend to name them
    <Something>Utils
    🤣 1
    c
    • 2
    • 1
  • e

    elect

    03/09/2018, 7:26 PM
    I found myself implementing various methods instead
    var
    with custom get and set methods because they are in an interface.. isn't there any other way?
    c
    a
    • 3
    • 13
  • a

    Andreas Sinz

    03/10/2018, 4:32 PM
    data class Foo private constructor (val a: Int, val b: Int)
    
    fun Foo(a: Int, b: Int) = ...
    s
    s
    • 3
    • 18
  • k

    karelpeeters

    03/10/2018, 6:52 PM
    Nevermind it does exist :rubber_duck:
    ❓ 1
    s
    • 2
    • 4
  • k

    Kulwinder Singh

    03/11/2018, 3:43 AM
    what if it do rounding or truncation of integer
    a
    • 2
    • 1
  • b

    betterclever

    03/11/2018, 8:57 AM
    any experienced Exposed DAO users here? I have a doubt.
    a
    • 2
    • 1
  • g

    galex

    03/11/2018, 11:10 AM
    Oh you are right. It does work like expected when I declare channel as NotificationChannel?, but when used with NotificationChannel! it does crash. Neat!
    i
    • 2
    • 1
  • r

    robstoll

    03/11/2018, 12:30 PM
    what is the correct way of using delegation in the context of an object? I tried this but get a compilation error, factory must to be initialized:
    object CoreFactory : ICoreFactory by factory {
        private val factory: ICoreFactory
    
        init {
            val loader = ServiceLoader.load(ICoreFactory::class.java)
            val itr = loader.iterator()
            check(itr.hasNext()) {
                "Could not find an implementation for ${ICoreFactory::class.java.name}"
            }
            factory = itr.next()
        }
    }
    o
    • 2
    • 6
  • s

    sudhanshu singh

    03/11/2018, 12:59 PM
    how can I solve this ‘no args’ issue
    c
    k
    g
    • 4
    • 12
Powered by Linen
Title
s

sudhanshu singh

03/11/2018, 12:59 PM
how can I solve this ‘no args’ issue
c

Czar

03/11/2018, 1:05 PM
what are you parsing it with? GSON?
s

sudhanshu singh

03/11/2018, 1:08 PM
yes
c

Czar

03/11/2018, 1:09 PM
You could try using InstanceCreator like GSON docs suggest, but GSON + Kotlin is not an ideal combination, I'd either use jackson with kotlin module registered or kotlin-specific lib, like klaxon or koshi
k

Konstantin

03/11/2018, 1:10 PM
Why don't you make it enum class then?
c

Czar

03/11/2018, 1:11 PM
Another problem here is
val type: MenuTypeModel
serializer will try to instantiate the parent instead of
MAP
,
CALENDAR
or
LEADERBOARD
which you probably want.
s

sudhanshu singh

03/11/2018, 1:12 PM
I am trying to avoid using enum in Android as it is recommended by many not to use enums
c

Czar

03/11/2018, 1:14 PM
It is recommended not to use Enums only to save up on memory and CPU when you can do the same thing with a constant, by using sealed classes you are defeating the purpose of avoiding enums
s

sudhanshu singh

03/11/2018, 1:15 PM
oh.
I should go back to using stringDef then.
c

Czar

03/11/2018, 1:18 PM
yeah, use of enum in this case is (probably) lighter than sealed classes 🙂 In the future always check why something is or isn't recommended.
👍 1
➕ 1
g

gildor

03/11/2018, 2:16 PM
In general It’s completely fine to use Enums on Android. If Enum or Sealed class solves your problem just use it. At least it’s more type safe than StringDef
👍 1
In your case I don’t see any reason to use Sealed class instead of Enum.
View count: 1