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
reflect
  • s

    snowe

    02/15/2017, 11:27 PM
    I can't find any documentation on how to compare KTypes with Class types.
    m
    u
    • 3
    • 6
  • p

    pabl0rg

    02/20/2017, 10:33 AM
    @udalov the code is here: https://github.com/pabl0rg/kobalt-dsl-documenter
    u
    • 2
    • 5
  • p

    pabl0rg

    02/20/2017, 10:35 AM
    Is there a way to get the default value of a KProperty?
    u
    • 2
    • 5
  • d

    dmcg

    02/27/2017, 1:57 PM
    So it was an error that
    this.javaClass
    didn’t have the
    out
    variance?
    u
    • 2
    • 1
  • a

    adambl4

    05/10/2017, 1:21 PM
    this code throws the
    NotImplementedError
    since
    1.1.2
    . Is this somewhere documented?
    test<Boolean>()
    
    inline fun <reified T : Any> test() {
            when(T::class) {
                Boolean::class -> {}
                else -> throw NotImplementedError()
            }
        }
    u
    • 2
    • 1
  • k

    kirillrakhman

    05/24/2017, 3:52 PM
    you can do that without language features
  • k

    kirillrakhman

    05/24/2017, 3:53 PM
    abstract class KnowsChildrenTypes() {
        companion object {
            val types = mutableSetOf<Class<out KnowsChildrenTypes>>()
        }
        
        init {
            types += this::class.java
        }
    }
    
    class Child1 : KnowsChildrenTypes()
    class Child2 : KnowsChildrenTypes()
    s
    • 2
    • 4
  • p

    pniederw

    05/24/2017, 11:59 PM
    and converting to
    Class
    has undesirable side effects (e.g. kotlin.String -> java.lang.String)
    i
    • 2
    • 2
  • d

    deinspanjer

    05/27/2017, 3:46 PM
    So.. next issue.. I was going to try using the call
    obj::class.simpleName
    , and it said I needed to add the reflection jar to do that. I added it to my Maven Dependencies, but now, when I try to run, I get this error, even if I take out the ::class thing and leave my code just as it was when it runs without the reflection jar:
    Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
    Exception Details:
      Location:
        kotlin/reflect/jvm/internal/ReflectionFactoryImpl.function(Lkotlin/jvm/internal/FunctionReference;)Lkotlin/reflect/KFunction; @5: invokestatic
      Reason:
        Type 'kotlin/jvm/internal/FunctionReference' (current frame, stack[2]) is not assignable to 'kotlin/jvm/internal/CallableReference'
      Current Frame:
        bci: @5
        flags: { }
        locals: { 'kotlin/reflect/jvm/internal/ReflectionFactoryImpl', 'kotlin/jvm/internal/FunctionReference' }
        stack: { uninitialized 0, uninitialized 0, 'kotlin/jvm/internal/FunctionReference' }
      Bytecode:
        0x0000000: bb00 1059 2bb8 0042 2bb6 0020 2bb6 0021
        0x0000010: 2bb6 001f b700 38b0                    
    
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:264)
    	at kotlin.jvm.internal.Reflection.<clinit>(Reflection.java:32)
    	at kotlin.io.ConsoleKt.<clinit>(Console.kt)
    	at com.jsonlogic.RunnerKt.readInput(Runner.kt:40)
    	at com.jsonlogic.RunnerKt.main(Runner.kt:14)
    u
    • 2
    • 1
  • s

    snowe

    07/10/2017, 8:02 PM
    Not sure if this was the best place to ask, but why is it not possible to accept a
    java.util.List<? extends Blah>
    type into a kotlin method that accepts a type of kotlins
    kotlin.collections.List<out Blah>
    ?
    u
    • 2
    • 1
  • d

    dszopa

    07/21/2017, 2:49 AM
    Specifically when I debug I see that the java type shows up as
    javaType!
    indicating it could be nullable or non nullable, where as the kotlin type shows up as `kotlinType?`indicating nullable
    u
    • 2
    • 1
  • m

    mp911de

    07/25/2017, 1:15 PM
    Hi there. Is there some documentation on Kotlin’s synthetic constructor generation along with default arguments (bitmask used for defaulting)?
    u
    • 2
    • 2
  • w

    wouterdoeland

    08/07/2017, 8:58 AM
    Hi, how should I check whether a KType is equal to another KType? For example: I want to check whether a parameter in the constructor of an object is a String
    u
    • 2
    • 1
  • g

    grandstaish

    08/26/2017, 2:15 AM
    I'm trying to debug why Moshi doesn't work with Kotlin + ProGuard. The issue I'm seeing is that when ProGuard is enabled the call
    rawType.kotlin.primaryConstructor
    returns
    null
    . What sorts of things do I need to keep in order for kotlin-reflect to be able to find the primary constructor of a class at runtime? Just keeping the
    @Metadata
    annotation methods (as the library suggests) is not enough. Keeping all kotlin classes (
    -keep class kotlin.** { *; }
    ) does work, but I'd rather just keep what I need.
    u
    • 2
    • 4
  • j

    janvladimirmostert

    09/09/2017, 10:04 AM
    I'm trying to invoke a function, but I 'm getting
    java.lang.IllegalArgumentException: Callable expects 4 arguments, but 3 were provided.
    This is the place where I'm doing the call:
    annotation.listeners.forEach { listener: KClass<*> ->
    					listener.functions.forEach { function: KFunction<*> ->
    						if (function.name == "before") {
    							function.call(annotation.action, request, response)
    						}
    					}
    				}
    And this is the method on the interface that's being called:
    interface ControllerListener {
    	fun before(action: String, request: RestRequest, response: RestResponse)
    	fun after(action: String, request: RestRequest, response: RestResponse)
    }
    What should the fourth paramater be?
    i
    • 2
    • 3
  • s

    snowe

    09/23/2017, 9:57 PM
    If I have a property that I'm trying to add a modifier to it works fine, as long as there is no annotation on that property. Why is that? otherwise I get an exception
    u
    • 2
    • 3
  • m

    Marc Knaup

    10/31/2017, 12:09 PM
    I wonder why
    .javaClass
    doesn’t use
    out
    projection 😮
    u
    • 2
    • 2
  • y

    yoavst

    11/10/2017, 10:20 AM
    Can I improve this code without full reflection jar (for android)? I want to be able to pass only
    boundReference::fieldName
    u
    • 2
    • 2
  • m

    miha-x64

    11/19/2017, 11:15 AM
    Any way to get actual type agruments from a reified type? E. g. in
    someInlineFunc<A<X>, A<Y>, B<X>>()
    , is there a way to say that first two type arguments are different? (Okay, I've resolved my task without it, now it's just a proof-of-concept question.)
    s
    • 2
    • 6
  • s

    snowe

    11/20/2017, 8:28 PM
    is there any way to declare functions programmatically with annotations on them?
    u
    • 2
    • 1
  • s

    sdeleuze

    11/23/2017, 1:20 PM
    I have found https://stackoverflow.com/a/33907581/1092077 from @udalov but slighly old response so maybe there is now a way to do that without using Jjava reflection ?
    u
    • 2
    • 1
  • n

    natpryce

    11/24/2017, 3:10 PM
    Hi. If I have a KClass<T>, how do I safely cast a value of type Any to a value of type T? I’m looking for a dynamic equivalent to the
    as?
    operator.
    u
    • 2
    • 3
  • d

    diesieben07

    12/08/2017, 5:04 PM
    I'm used to something like
    getDeclaringClass
    from Java.
    kotlin.jvm.internal.CallableReference
    has
    getOwner
    , but that is internal API and only available for references...
    u
    • 2
    • 4
  • m

    mp911de

    01/17/2018, 4:21 PM
    Hey there, is there a public API to discover the kind (
    CLASS
    ,
    FILE_FACADE
    , …) of a Kotlin class?
    u
    • 2
    • 1
  • b

    beholder

    01/18/2018, 5:35 PM
    Is there analog of
    Class.getEnclosingClass()
    for
    KClass
    ?
    u
    • 2
    • 1
  • b

    benny.huo

    01/18/2018, 10:43 PM
    Hey guys. I have a problem using kotlin-reflect with proguard. I called
    superTypes
    to retrieve superTypes of
    RepoListFragment
    while its superClass
    CommonListFragment
    was mapped to
    com.bennyhuo.github.view.common.b
    . The runtime crash:
    java.lang.IllegalStateException: Incomplete hierarchy for class RepoListFragment, unresolved classes [com.bennyhuo.github.view.common.CommonListFragment]
    at kotlin.reflect.jvm.internal.components.RuntimeErrorReporter.reportIncompleteHierarchy(RuntimeErrorReporter.kt:26)
    at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassTypeConstructor.computeSupertypes(DeserializedClassDescriptor.kt:187)
    After hours of searching I found that kotlin-reflect get the type infomation from the annotation
    Metadata
    while the value of it may not be processed by proguard.
    @Metadata(
       mv = {1, 1, 7},
       bv = {1, 0, 2},
       k = 1,
       d1 = {"..."},
       d2 = {"Lcom/bennyhuo/github/view/fragments/subfragments/RepoListFragment;", "Lcom/bennyhuo/github/view/common/CommonListFragment;", "Lcom/bennyhuo/github/network/entities/Repository;", "Lcom/bennyhuo/github/presenter/RepoListPresenter;", "()V", "adapter", "Lcom/bennyhuo/github/view/fragments/RepoListAdapter;", "getAdapter", "()Lcom/bennyhuo/github/view/fragments/RepoListAdapter;", "production sources for module app"}
    )
    Any suggestions or workaround?😳
    u
    z
    • 3
    • 5
  • a

    albertgao

    01/23/2018, 4:24 AM
    I got a
    param.type === nz.salect.objJSON.JVMBranchTest.MenuObject?
    where
    param:KParameter
    . But when I tried to get the class definition from
    param.type
    via
    param.type::class
    . Instead of getting the above
    MenuObject
    , I get a
    class kotlin.reflect.jvm.internal.KTypeImpl
    . How to get my own class , I mean, a
    KClass
    ? Thanks 🙂
    u
    • 2
    • 4
  • a

    albertgao

    01/23/2018, 5:26 AM
    How to check whether the type of objects inside a
    List<*>
    is a kotlin official class or my own class, I currently check its name:
    paramName.substring(24).removeSuffix(">")
    , so
    "kotlin.collections.List<nz.salect.objJSON.Lesson>"
    will become
    "nz.salect.objJSON.Lesson"
    , and then I can verify whether it
    startsFrom("kotlin")
    or not. What’s a better way to do this?
    u
    • 2
    • 5
  • s

    snowe

    01/27/2018, 12:05 AM
    yeah I didn't want to do that, wasn't sure if kotlin was capable of it. thanks!
    g
    • 2
    • 1
  • g

    groostav

    02/02/2018, 1:29 AM
    given a
    KProperty1
    instance, is it possible to know if its declaration is backed by a delegate?
    d
    • 2
    • 1
Powered by Linen
Title
g

groostav

02/02/2018, 1:29 AM
given a
KProperty1
instance, is it possible to know if its declaration is backed by a delegate?
d

diesieben07

02/02/2018, 8:23 AM
There's a
getDelegate
function on
KProperty1
.
☝️ 1
View count: 1