package javassist.test; import javassist.ClassPool; import javassist.CtClass; public class ExtendSample { public static void main(String[] args) throws Exception{ ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("dynamic.clazz.Sample"); cc.setSuperclass(pool.get("java.lang.String")); Class<?> clazz = cc.toClass(); Object obj = clazz.newInstance(); } } Exception in thread "main"
![Javassistを使ってJavaのfinalクラスの拡張は・・・ - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/6e815cc32db6b31e641fe06ec56eea262aeaa21d/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZoPTMzNiZ0eHQ9SmF2YXNzaXN0JUUzJTgyJTkyJUU0JUJEJUJGJUUzJTgxJUEzJUUzJTgxJUE2SmF2YSVFMyU4MSVBRWZpbmFsJUUzJTgyJUFGJUUzJTgzJUE5JUUzJTgyJUI5JUUzJTgxJUFFJUU2JThCJUExJUU1JUJDJUI1JUUzJTgxJUFGJUUzJTgzJUJCJUUzJTgzJUJCJUUzJTgzJUJCJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LWNsaXA9ZWxsaXBzaXMmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz0xZDIxMTFlZTUyZjY3Njg2M2QxZWY4Y2U4YjBkNWE3NA%26mark-x%3D142%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTYxNiZ0eHQ9JTQwa3Vyb2dlbGVlJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9MzYmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz0xNzYwYTdkOTNjMmNjMGIxZjRiNDU5N2JlMjQwMWQxNQ%26blend-x%3D142%26blend-y%3D491%26blend-mode%3Dnormal%26s%3Db4160497de015e1bc425e94e9ede7c8a)