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

    juancho

    11/17/2018, 6:54 PM
    Hi everyone! Does anyone know how to get the “default value” from a constructor parameter using annotation processor and kotlin-metadata? Example:
    class Foo(val bar: Int = 1)
    how do I get the value
    1
    ?
    e
    • 2
    • 13
  • n

    natpryce

    11/25/2018, 10:11 AM
    On the JVM platform, there’s a reflection API function that returns the Kotlin property that corresponds to a field. Is there a way to get the Kolin property that corresponds to the JVM method that is the property’s getter?
    d
    • 2
    • 1
  • v

    v79

    12/05/2018, 9:03 PM
    I'm trying to load some classes dynamically at runtime, which should all implement a specific interface,
    GeneratorPipeline
    . Given a String array of class names, I'd like the corresponding array of KClass objects. But this fails on line 7
    processorPipeline.add(kClass)
    as
    kClass
    is of type
    KClass<out Any!>
    . Any ideas? Loosening the array
    processorPipeline = arrayListOf<KClass<*>>()
    is OK, but ultimately I need
    Array<KClass<GeneratorPipeline>>
    Building_an_array_of_KClass__.kt
    • 1
    • 1
  • m

    Marc Knaup

    12/06/2018, 12:21 AM
    /**
     * JVM internal name of the class, where package names are separated by '/', and class names are separated by '$',
     * for example: `"org/foo/bar/Baz$Nested"`
     */
    val ClassName.jvmInternalName: String
        get() =
            if (this.isLocal) substring(1)
            else replace('/', '$')
    Isn't it supposed to replace
    .
    with
    $
    , not
    /
    with
    $
    ?
    g
    i
    • 3
    • 3
  • m

    Marc Knaup

    12/10/2018, 11:33 PM
    Why does this work:
    val m = JSONParser::class.java.getAnnotation(Metadata::class.java)
    but this returns `null`:
    val m = JSONParser::class.findAnnotation<Metadata>()
    🤔
    u
    • 2
    • 2
  • c

    christophsturm

    12/11/2018, 8:25 PM
    is it possible to get the kclass for a ktype?
    d
    • 2
    • 2
  • d

    diesieben07

    12/29/2018, 3:09 PM
    Mutable/Not-Mutable handling of collection classes seems to be very inconsistent:
    val x: MutableCollection<String> get() = TODO()
    fun main() {
      println(MutableCollection::class) // prints "class kotlin.collections.Collection
      println(Set::class.isSubclassOf(MutableCollection::class)) // prints true, should be false
      println(::foo.returnType) // prints kotlin.collections.MutableCollection<kotlin.String>, yay!
      println(::foo.returnType.classifier) // prints kotlin.collections.Collection, :(
    }
    Is there any way to figure out if a KType represents a mutable collection type?
    g
    u
    • 3
    • 4
  • d

    DALDEI

    01/05/2019, 3:32 PM
    Would it be considered a bug that kotlin calculates a different property name for a java class then standard Java Beans properties code does ? Example String getURL() JavaBeans : "URL" Kotlin: "uRL" EDIT: I created KT-29123
    b
    g
    • 3
    • 2
  • d

    Davide Giuseppe Farella

    01/21/2019, 10:27 AM
    I’m looking at the docs of
    KFunction
    and I’m wondering why only Jvm has
    instanceParameter
    and
    valueParameters
    . How does that work on Native? Should I suppose all the
    parameters
    are valueParameters or maybe it’s just not implemented yet and I should distinct them by myself ( how? ) ? P.S. I don’t know much about Native, that’s the reason of the dumb question
    u
    • 2
    • 2
  • g

    groostav

    01/25/2019, 10:35 AM
    Hey guys, I'm trying to convert a method reference like
    SomeClass::main
    into a classname for a
    java -mainClass
    argument. This is the best I've got
    private val KFunction<*>.instanceTypeName: String get() {
        return ((this as FunctionReference).boundReceiver::class as KClass<*>).jvmName
    }
    usage:
    val mainClass: String = (MyType::main).instanceTypeName
    is there a better solution?
    b
    u
    • 3
    • 3
  • d

    dmcg

    02/12/2019, 11:31 AM
    What I'm really trying to do is to get a
    KFunction0
    by applying a receiver to a
    KFunction1
    returned from
    this::class::memberFunctions
    - is that possible?
    g
    • 2
    • 1
  • d

    diesieben07

    02/13/2019, 11:20 PM
    Unfortunately there are not many reflection capabilities for JS yet and same for Native.
    z
    • 2
    • 2
  • n

    Nikky

    02/27/2019, 12:19 PM
    seems like whenever i want to pass a DataFrame to something using reflection, this happens:
    Exception in thread "main" java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    u
    • 2
    • 2
  • d

    dewildte

    02/27/2019, 11:35 PM
    -.txt
    n
    • 2
    • 17
  • l

    LeoColman

    03/04/2019, 6:36 PM
    Hi, how to obtain all functions that have a functional parameter using Kotlin Reflect? I tried something like
    Class.forName("myClass").declaredMethods.map { it.kotlinFunction!! }.filter { fn -> fn.parameters.any { it is KFunction<*> } }
    but it didn't work
    u
    • 2
    • 4
  • j

    jdiaz

    03/05/2019, 11:23 AM
    How would you instantiate a data class (probably with val) if you have the property names as string and the values with the correct type? I can't wrap my mind around it
    d
    d
    • 3
    • 10
  • m

    Marc Knaup

    03/05/2019, 7:38 PM
    🎉 looks like
    typeOf
    is coming soon 😄 Goodbye type tokens! https://youtrack.jetbrains.com/issue/KT-29915#focus=streamItem-27-3323738.0-0
    g
    • 2
    • 2
  • p

    pniederw

    03/08/2019, 11:31 PM
    How do I reflectively instantiate an enum given an enum class of type
    java.lang.Class<*>
    ? Can't find a way to make the type checker happy.
    m
    j
    +2
    • 5
    • 12
  • g

    groostav

    03/13/2019, 7:52 PM
    Hey guys, regarding extension functions and reflection, is there a generally accepted solution to "search" for extension functions given you only have an instance? What about an instance and a couple package names?
    u
    • 2
    • 1
  • g

    gregorbg

    06/03/2019, 3:06 PM
    Is there any smart way to achieve the following?
    class MyClass<E: Enum<E>>(val name?) {
        fun read(source: MagicalStringSupplier): E? = source.read()?.let { enumValueOf(it) }
    }
    I fully understand that the above example does not compile because the type of
    E
    is a class type parameter that gets erased during runtime. I fully appreciate that there is no way to reify
    E
    currently, but perhaps there's a more "dirty" way involving passing around a
    KClass<E>
    or (worst case) even a Java
    Class<E>
    ? We badly need such a feature when reading configurations from files, so that we don't have to constantly convert strings to enums all the time 😇
    i
    • 2
    • 1
  • p

    Pickle

    06/24/2019, 5:49 PM
    AreYouACollection_.txt
    m
    • 2
    • 1
  • s

    SrSouza

    07/28/2019, 5:31 PM
    Hi guys, my setter is not working with private set properties Without the private in the object, works fine
    val setter = prop.setter.apply { isAccessible = true } // line 52
    setter.call( // line 53
      instance,
      adapter(
        instance,
        prop,
        if (any is Number) fixNumberType(prop, any) else any
      )
    Untitled
    • 1
    • 1
  • d

    dmcg

    08/03/2019, 9:55 PM
    Is there anything in the stdlib that captures the class and nullability of a type?
    d
    • 2
    • 4
  • d

    DALDEI

    08/09/2019, 2:15 AM
    Given an object instance and class is there a way to bind the class member properties to the instance to produce a bound property reference ? E.g. convert a KProperty1 to a KProperty0 Say ``` fun bind( obj: Any ) : List<KProperty0<*>> { val props1= obj::class.memberProperties // KProperty1<T,R> return props.map { bind( it , obj ) ???? } // KProperty0<R> } I can do this: fun bin( knownObject: MyClass ) = listOf( knownObject::prop1 , knownObject::prop2 , ...) But cant find a way to do so generically (without enumerating each property by name/accessor )
    u
    • 2
    • 2
  • d

    Dariusz Kuc

    09/12/2019, 6:20 PM
    hello, does anyone know whether this change was intentional? Java 8 + Kotlin 1.3.31 ->
    println({}::class.simpleName)
    ->
    null
    Java 8 + Kotlin 1.3.40+ -> automatically generates numeric names
    "1"
    (and increments it for subsequent anonymous classes) Java 11 ->
    null
    ➕ 1
    • 1
    • 2
  • p

    pniederw

    09/18/2019, 11:34 PM
    Does kotlin-reflect-1.3.x have known JDK 11 incompatibilities? Our static analyzer claims it's using JDK APIs that aren't available in 11 (unfortunately I don't have details).
    u
    • 2
    • 1
  • n

    nils

    10/02/2019, 5:17 PM
    Hello, I'm currently working on a framework, which uses reflection to parse and introspect functions. I'm aware that Kotlin applies type erasure to generics during runtime (effectively turning
    SomeClass<Type>
    into
    SomeClass<*>
    ). However, I'd expect type checks such as the one outlined below to correctly yield
    true
    . I'd like to ask if the below code snippet is a mistake on my end or if it's related to some kind of bug related to invariances. Thank you.
    Test.kt
    s
    b
    • 3
    • 2
  • i

    ildar.i [Android]

    01/09/2020, 10:53 AM
    Hi! Had to move method from class to extention and now it throws
    java.lang.IllegalAccessException: Class clean.db.entities.LocalizationDbEntityKt can not access a member of class infin.api.core.legal.entities.auth.login.LocalizationFromServer with modifiers "private final"
    fun LocalizationFromServer.toList() = LocalizationFromServer::class.java.declaredFields.map {
        LocalizationDbEntity(it.name, it.get(this)?.toString())
    }
    Cah anyone help pls?
    r
    • 2
    • 2
  • i

    int02h

    01/10/2020, 11:59 AM
    Hi! Did I understand it right that kotlin-reflect extracts information about class (for example member names) from its
    @Metadata
    annotation? Because I can extract class member original names even if ProGuard/R8 has obfusacted the class. Does it make reverse engineering easier because bytecode of the class contains information about its members in
    @Metadata
    annotation?
    d
    t
    • 3
    • 21
  • e

    Eugen Martynov

    03/18/2020, 4:28 PM
    Probably already asked many times, how can I workaround issue
    java.lang.AssertionError: Built-in class kotlin.Any is not found
    Or it is fixed already?
    u
    • 2
    • 2
Powered by Linen
Title
e

Eugen Martynov

03/18/2020, 4:28 PM
Probably already asked many times, how can I workaround issue
java.lang.AssertionError: Built-in class kotlin.Any is not found
Or it is fixed already?
u

udalov

03/22/2020, 1:08 PM
If you reshade/jarjar the standard Kotlin library into your application, make sure to keep the
**/*.kotlin_builtins
files, since that's where metadata for these classes is located
e

Eugen Martynov

03/25/2020, 2:40 PM
Thank you!!!
View count: 8