Tag: 类加载器

Kotlin:MyClass :: class.java vs this.javaClass

我正在将一个项目迁移到Kotlin,而这个: public static Properties provideProperties(String propertiesFileName) { Properties properties = new Properties(); InputStream inputStream = null; try { inputStream = ObjectFactory.class.getClassLoader().getResourceAsStream(propertiesFileName); properties.load(inputStream); return properties; } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } 就是现在: fun […]

Kotlin类重新加载伴侣对象/函数

我正在尝试Kotlin类的重新加载,但最近我遇到了一些与之相关的东西: package com.aurieh.reloading fun doSomething(): String { // a function that does not belong to the class, // so it gets compiled as FileName$doSomething$… } class FileName { // do things with doSomething } 如果我重新加载这个类(使用ImplClassLoader.defineClass和ByteArray ),并尝试调用内部调用doSomething的方法,我得到一个错误类似于: java.lang.IllegalAccessError: tried to access method com.aurieh.reloading.FileName.doSomething$default()Ljava/lang/String; from class com.aurieh.ares.reloading.FileName` 我会解释这个好像重新加载的类没有附加任何东西。所以我的问题是,我将如何解决这个错误? 以某种方式附加doSomething重装类加载器? 作为参考,我的类重载代码: class Reloader : ClassLoader() { fun load(name: […]