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/

相关推荐
大貔貅喝啤酒29 分钟前
Python Requests库教程
自动化测试·python·requests库
copyer_xyf1 小时前
LangChain 调用 LLM
后端·python·agent
copyer_xyf1 小时前
Prompt 组织管理
后端·python·agent
asdfg12589631 小时前
JavaBean是什么?怎么理解?有什么用途?
java·开发语言
dsyyyyy11012 小时前
JavaScript变量
开发语言·javascript·ecmascript
shimly1234562 小时前
python3 uvicorn 是啥?
python
z落落3 小时前
C#WinForm 窗体切换与窗体传值(登录跳转案例)+WinForm 窗体传值(从上往下传、从下往上传)
开发语言·windows·c#
CTA量化套保3 小时前
期货量化程序 time.sleep 卡死:天勤单线程与 deadline 替代
python·区块链
allway23 小时前
How to Echo Multiline to a File in Bash [3 Methods]
开发语言·chrome·bash
weixin_462446233 小时前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash