JVM学习笔记16——类加载器重要方法详解
发布日期:2021-06-29 01:18:52 浏览次数:2 分类:技术文章

本文共 1512 字,大约阅读时间需要 5 分钟。

defineClass详解

protected final Class<?> defineClass(String name,

                                     byte[] b,
                                     int off,
                                     int len)
                             throws ClassFormatError
Converts an array of bytes into an instance of class Class. Before the Class can be used it must be resolved.
This method assigns a default ProtectionDomain to the newly defined class. The ProtectionDomain is effectively granted the same set of permissions returned when Policy.getPolicy().getPermissions(new CodeSource(null, null)) is invoked. The default domain is created on the first invocation of defineClass, and re-used on subsequent invocations.
To assign a specific ProtectionDomain to the class, use the defineClass method that takes a ProtectionDomain as one of its arguments.

Parameters:
name - The expected binary name of the class, or null if not known
b - The bytes that make up the class data. The bytes in positions off through off+len-1 should have the format of a valid class file as defined by The Java™ Virtual Machine Specification.
off - The start offset in b of the class data
len - The length of the class data

Returns:
The Class object that was created from the specified class data.

Throws:
ClassFormatError - If the data did not contain a valid class
IndexOutOfBoundsException - If either off or len is negative, or if off+len is greater than b.length.
SecurityException - If an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class (which is unsigned), or if name begins with "java.".

转载地址:https://blog.csdn.net/yshuoo/article/details/116520105 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:JVM学习笔记17——类加载器双亲委托机制实力剖析
下一篇:JVM学习笔记15——自定义类加载器深入详解

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月15日 01时44分41秒