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/

相关推荐
goyeer12 小时前
Liunx日志管理与journalctl
java·linux·运维·服务器·运维开发·信息化·信息化企业管理
卷无止境12 小时前
FastAPI 后台任务的边界,以及 Celery、Redis 与自建调度系统的选择
后端·python
NoteStream12 小时前
MATLAB绘制带置信区间的折线散点图(科研绘图模板)
开发语言·matlab
卷无止境12 小时前
Linux + Docker + FastAPI 工程化实践指南
后端·python·fastapi
tianyu23414 小时前
Java 正则表达式终极指南:从 Pattern 到 Matcher,从双重转义到性能优化,一篇全搞定
java·开发语言·正则表达式·group·find·pattern·matcher
caimouse15 小时前
ReactOS 窗口系统分析(23):键盘 — keyboard.c + kbdlayout.c
c语言·开发语言·计算机外设
Emily1568535987016 小时前
Emerson 1C31129G03 Analog Input Module
java·开发语言·前端·plc·emerson·1c31129g03·input module
就叫_这个吧20 小时前
Java递归方法实现面包屑导航
java·开发语言
fīɡЙtīиɡ ℡21 小时前
AI 应用系统设计
java·开发语言·人工智能
城管不管21 小时前
重生——第十一次面试之挖财一面2026.8.19已OC
java·服务器·jvm·数据库·spring·面试·职场和发展