hutool java代码字符串动态加载类

java 复制代码
public class Test {
    public static void main(String[] args) throws Exception {
        ClassLoader compile = CompilerUtil.getCompiler(null)
                .addSource("Hello", "public class Hello{public static void main(String[] args){System.out.println(\"Hello World!\");}}")
                .compile();
        Class<?> hello = compile.loadClass("Hello");
        // 实例化对象c
//        Object obj = ReflectUtil.newInstance(hello);
        hello.getMethod("main", String[].class).invoke(null, (Object) new String[]{});
    }
}

https://doc.hutool.cn/pages/CompilerUtil/

相关推荐
山栀shanzhi几秒前
C/C++之:构造函数为什么不能设置为虚函数?
开发语言·c++·面试
lsx2024062 分钟前
.toggleClass() 方法详解
开发语言
yuan199978 分钟前
C&CG(列与约束生成)算法,来解决“风光随机性”下的微网鲁棒配置问题
c语言·开发语言·算法
SamDeepThinking9 分钟前
别让一个超时的第三方http接口拖垮所有接口
java·后端·架构
李白的天不白17 分钟前
读到数据为undefind是的几种情况
开发语言·javascript·ecmascript
YaBingSec20 分钟前
玄机靶场:供应链安全-供应链应急-Part2 通关笔记
java·笔记·安全
迷途酱22 分钟前
手写一个 AI Agent:从 Function Calling 到自动化任务链
python
Gerardisite23 分钟前
企微机器人开发指南
java·python·机器人·自动化·企业微信
OtIo TALL26 分钟前
Java进阶(ElasticSearch的安装与使用)
java·elasticsearch·jenkins
LeocenaY32 分钟前
C语言面试题总结
c语言·开发语言·数据结构