Tag: kotlin reflect

在Spring Boot M7和MongoDB中找不到ReflectKotlinClass

如果使用Web和MongoDB模块在start.spring.io上创建一个新的Spring Boot项目,请添加任何@Document注释类,并且将kotlin.version从1.2.10升级到1.2.21,您将得到一个NoClassDefFoundError: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M7:run (default-cli) on project demo: An exception occurred while running. null: InvocationTargetException: Error creating bean with name ‘mongoTemplate’ defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method ‘mongoTemplate’ parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘mappingMongoConverter’ defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied […]

在Kotlin Android Library Project中获取未解决的引用错误

Kotlin Android Library项目中出现未解决的引用错误。 1.)standard_kotlin_lib.jar – >包含:Kotlin类,META-INF / standard_kotlin_lib.kotlin_module 2.)A.aar – >仅编译standard_kotlin_lib.jar文件。 编译完成后,在生成的.aar文件的classes.jar里面:缺少META-INF / standard_kotlib_lib.kotlin_module,感染整个META-INF缺失 3.)B.ar – >汇编A.aar。 这里,kotlin源代码导入类在“standard_kotlin_lib.jar”中定义。 导入时出现未解决的引用错误 B.aar < – A.aar < – standard_kotlin_lib.jar 工具版本:1)我正在使用android gradle插件3.0.0和gradle版本4.3.0。 与以前的插件版本,即2.2.3和gradle版本3.2.1,这个错误没有到来。 Kotlin版本是1.1.4 问题我认为:1.)A.aar文件中缺少META-INF。 当我在A.aar的classes.jar中手动复制META-INF时,B.aar编译成功。

我如何使用Kotlin中的默认构造函数参数值实例化一个对象?

我有数据类与默认值。 data class Project( val code: String, val name: String, val categories: List<String> = emptyList()) 当某些值为null时,Java反射无法实例化类。 我得到例外 java.lang.IllegalArgumentException: Parameter specified as non-null is null: method Project.<init>, parameter categories 这是因为java.lang.reflect.Constructor<T>.instantiateClass方法需要非空的参数。 我有类型信息,我有构造函数的定义,但我不知道如何调用构造函数,以便它使用默认值(值来自数据库和categories可以为null )。 Kotlin有没有办法达到这个目的?

Kotlin在Android上使用MultiDex进行授权,低于21

我有以下代表… fun integerPref(initialValue: Int) = object : ObservableProperty<Int>(initialValue) { override fun afterChange(property: KProperty<*>, oldValue: Int, newValue: Int) { getSharedPreference(INTEGER_PREF, EasyInjection.mode) .edit() .putInt(property.toString(), newValue) .apply() } override fun getValue(thisRef: Any?, property: KProperty<*>): Int { return getSharedPreference(INTEGER_PREF, EasyInjection.mode) .getInt(property.toString(), initialValue) } } 这位代表的目的是处理股票的偏好。 当我的应用程序变成MultiDex时,问题就发生了 。 当我在下面的代码中使用它时,应用程序崩溃。 class IntroduceActivity : BaseActivity() { private val CURRENT_VERSION = 1 private […]