dstarcev
02/14/2018, 4:03 PMPerson
having a map of constructor arguments?
data class Person(val id: Int, val name: String, val age: Int?)
val args = mapOf("id" to 1, "name" to "Alice")
val newPerson = ???
Martin Weigel
02/16/2018, 8:37 AMdiesieben07
03/23/2018, 10:01 AMKType.classifier
will give you that, but it does not have to be a KClass
, it could be a KTypeParameter
. There is also KType.jvmErasure
, which will loose type information though.aaverin
03/28/2018, 10:02 AMtry {
val field = javaClass.getDeclaredField("mShiftingMode")
field.isAccessible = true
field.set(this, enable)
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}
I looked into kotlin-reflect, but can’t find a way to make private property publicbeholder
03/28/2018, 5:21 PMUnsupported [reference to the synthetic extension property for a Java get/set method]
- but is it possible get KProperty manually for plain Java class?v79
03/30/2018, 7:42 PMbdawg.io
04/02/2018, 8:27 PMclass MyClass(val first: String, val second: Int, val third: Boolean = false)
, is there a way to reference the variant of the constructor that would provide (String, Int) -> MyClass
as KFunction2<String, Int, MyClass>
?v79
04/07/2018, 3:43 PMclass MyClass(val aList: List<String>)
the KParameter.type is List
. Is it ever possible for List
to have more than one argument?v79
04/12/2018, 6:40 PMAny?
object to an arbitrary KClass
. Here's what I would like to do:
fun Request.bind(modelClass: KClass<*>): Any? {
return WebForm(this,modelClass).get() as modelClass
}
I'd like to avoid having to type val person: Person = request.bind(Person::class) as Person
- that's a lot of references to Person
in a single line of code.dstarcev
04/17/2018, 6:56 PM@Metadata
dstarcev
04/19/2018, 9:57 AMmbickel
04/19/2018, 10:53 AMKClass.memberProperties
- the docs say I get a Collection<KProperty1<T, *>>
, but when I iterate this, the compiler infers KProperty1<out T, Any?>
, which prevents me from calling it.get(this)
on it. Anybody know why?diesieben07
04/23/2018, 9:43 AMKProperty1<T, R>
to a KProperty0<R>
when I have the receiver object (T
)? I.e., can I "bind" a receiver to a property?Danny
05/11/2018, 10:35 PMcodyoss
06/11/2018, 6:49 PMis
check on reified T : Any
at runtime?codyoss
06/22/2018, 4:46 AMsnowe
07/17/2018, 5:02 PMgroostav
08/04/2018, 5:17 AMske
08/08/2018, 11:59 PMkennyyi
08/11/2018, 5:58 AMfun foo(clazz: Class<*>) {
// 1. How to know clazz is collection?
// 2. How to know T of Collection<T> is String?
}
fun myFunc() {
val mySet: HashSet<String> = HashSet()
foo(mySet::class.java)
}
diesieben07
08/13/2018, 9:05 PMfun <T : Any> getFieldValues(obj: T): List<Any?> {
val cls = obj::class
return cls.memberProperties.map { it.get(obj) }
}
But this does not compile, because I am getting KClass<out T>
for cls
. Is there any way to do this in a type-safe manner?jdiaz
08/19/2018, 9:01 PMGabriel Machado
08/24/2018, 12:40 PMClass.forName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl")
is throwing java.lang.VerifyError: Bad type on operand stack
, anyone know how to solve this?diesieben07
08/25/2018, 1:39 PMKFunction
via a function reference, how do you resolve an "overload resolution ambiguity"?
I am trying to get a KFunction<String>
for ResultSet::getString
, but there are two versions of that (getString(Int)
and getString(String)
). How do I tell the compiler I want the Int
version?holgerbrandl
09/24/2018, 9:19 AMribesg
10/10/2018, 9:51 AMconst val
property?juancho
10/28/2018, 6:36 PM@MyAnnotation
internal class Car
So I thought using Kotlin Reflection I would be able to get this information but no luck.
Any clues on how to do it?SrSouza
11/01/2018, 2:56 PM[11:53:05 ERROR]: Error occurred while enabling KotlinBukkitAPI v0.1.0-SNAPSHOT (Is it up to date?)
java.lang.IllegalAccessError: tried to access method kotlin.collections.ArraysKt___ArraysJvmKt.copyOfRange([Ljava/lang/Object;II)[Ljava/lang/Object; from class kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:217) ~[?:?]
at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106) ~[?:?]
at kotlin.reflect.jvm.internal.KMutableProperty1Impl.set(KProperty1Impl.kt:59) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadRecursive(ConfigDSL.kt:392) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadAndSetDefaultR(ConfigDSL.kt:142) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.dsl.config.KConfig.loadAndSetDefault(ConfigDSL.kt:96) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.dsl.config.ConfigDSLKt.loadAndSetDefault(ConfigDSL.kt:63) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.dsl.config.ConfigDSLKt.loadAndSetDefault$default(ConfigDSL.kt:61) ~[?:?]
at br.com.devsrsouza.kotlinbukkitapi.KotlinBukkitAPI.onEnable(KotlinBukkitAPI.kt:25) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) ~[1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at br.com.devsrsouza.pluginlauncher.Main.lambda$onEnable$0(Main.java:32) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Serge
11/08/2018, 10:08 PMval o = object{}
val mm = o.javaClass.declaredMethods
and val mm = o::class
val ff = mm.declaredMemberFunctions
but it doesn't return anything. is it possible at all? if so, would the function modifier affect this search (private, public, etc)?