ClassLoader.DefineClass 方法

定义

重载

DefineClass(Byte[], Int32, Int32)
已过时.

将字节数组转换为 类 Class的实例。

DefineClass(String, ByteBuffer, ProtectionDomain)

使用java.nio.ByteBuffer <tt>ByteBuffer</tt>可选的 ProtectionDomain将 转换为类 Class的实例。

DefineClass(String, Byte[], Int32, Int32)

将字节数组转换为 类 Class的实例。

DefineClass(String, Byte[], Int32, Int32, ProtectionDomain)

使用可选的 ProtectionDomain将字节数组转换为 类 Class的实例。

DefineClass(Byte[], Int32, Int32)

注意

deprecated

将字节数组转换为 类 Class的实例。

[Android.Runtime.Register("defineClass", "([BII)Ljava/lang/Class;", "")]
[System.Obsolete("deprecated")]
protected Java.Lang.Class? DefineClass (byte[]? b, int off, int len);
[<Android.Runtime.Register("defineClass", "([BII)Ljava/lang/Class;", "")>]
[<System.Obsolete("deprecated")>]
member this.DefineClass : byte[] * int * int -> Java.Lang.Class

参数

b
Byte[]

构成类数据的字节。 位置通过的offoff+len-1字节应采用引用>Java&交易所定义的<有效类文件的格式;虚拟机规范</引用>。

off
Int32

类数据的起始偏移量b

len
Int32

类数据的长度

返回

Class 指定的类数据创建的 对象

属性

例外

如果 不包含有效的类,则 classRep 为 。

如果 offset 为 ,则为 ; length 如果 offset + length 大于 的 classRep长度,则为 。

注解

将字节数组转换为 类 Class的实例。 Class必须先解析才能使用 。 此方法已弃用,改用采用二进制名称作为其第一个参数的版本,并且更安全。

此成员已弃用。 替换为 #defineClass(String, byte[], int, int) defineClass(String, byte[], int, int)

java.lang.ClassLoader.defineClass(byte[], int, int)Java 文档。

此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。

适用于

DefineClass(String, ByteBuffer, ProtectionDomain)

使用java.nio.ByteBuffer <tt>ByteBuffer</tt>可选的 ProtectionDomain将 转换为类 Class的实例。

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, Java.Nio.ByteBuffer? b, Java.Security.ProtectionDomain? protectionDomain);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", "")>]
member this.DefineClass : string * Java.Nio.ByteBuffer * Java.Security.ProtectionDomain -> Java.Lang.Class

参数

name
String

预期的二进制名称。 类的 ;如果未知, null 则为

b
ByteBuffer

构成类数据的字节。 从位置b.position()到 位置b.position() + b.limit() -1 的字节应采用引用 Java&交易所定义的<>有效类文件的格式;虚拟机规范</引用>。

protectionDomain
ProtectionDomain

类的 ProtectionDomain 或 null

返回

Class 数据创建的 对象,可选 ProtectionDomain

属性

例外

如果 不包含有效的类,则 b 为 。

如果 className 不等于 中包含的 b类的名称,则为 。

注解

使用java.nio.ByteBuffer <tt>ByteBuffer</tt>可选的 ProtectionDomain将 转换为类 Class的实例。 如果域为 null,则默认域将分配给 文档 #defineClass(String, byte[], int, int)中指定的 类。 必须先解析类,然后才能使用该类。

有关包中定义的第一个类的规则(用于确定包的证书集)和类名的限制与 文档 #defineClass(String, byte[], int, int, ProtectionDomain)中指定的规则相同。

调用 clname,bBuffer,pd)形式的.defineClass(此方法会生成与 语句完全相同的结果

...<br> byte[] temp = new byte[bBuffer.java.nio.ByteBuffer#remaining remaining()];<br> bBuffer.java.nio.ByteBuffer#get(byte[]) get(temp);<br> return #defineClass(String, byte[], int, int, ProtectionDomain) cl.defineClass(name, temp, 0, temp.length, pd);<br>

在 1.5 中添加。

java.lang.ClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.ProtectionDomain)Java 文档。

此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。

适用于

DefineClass(String, Byte[], Int32, Int32)

将字节数组转换为 类 Class的实例。

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, byte[]? b, int off, int len);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;", "")>]
member this.DefineClass : string * byte[] * int * int -> Java.Lang.Class

参数

name
String

类的预期二进制名称;如果未知,则 null

b
Byte[]

构成类数据的字节。 位置通过的offoff+len-1字节应采用引用>Java&交易所定义的<有效类文件的格式;虚拟机规范</引用>。

off
Int32

类数据的起始偏移量b

len
Int32

类数据的长度

返回

Class 指定的类数据创建的 对象。

属性

例外

如果 不包含有效的类,则 classRep 为 。

如果 offset 为 ,则为 ; length 如果 offset + length 大于 的 classRep长度,则为 。

注解

将字节数组转换为 类 Class的实例。 Class必须先解析才能使用 。

此方法将默认值 java.security.ProtectionDomain <tt>ProtectionDomain</tt> 分配给新定义的类。 ProtectionDomain实际上会向 授予调用 时java.security.Policy#getPermissions(java.security.CodeSource) <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>返回的相同权限集。 默认域在 首次调用 #defineClass(String, byte[], int, int) <tt>defineClass</tt>时创建,并在后续调用中重新使用。

若要向 类分配特定的 ProtectionDomain ,请使用 #defineClass(String, byte[], int, int, java.security.ProtectionDomain) <tt>defineClass</tt> 采用 ProtectionDomain 作为其参数之一的方法。

在 1.1 中添加。

java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int)Java 文档。

此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。

适用于

DefineClass(String, Byte[], Int32, Int32, ProtectionDomain)

使用可选的 ProtectionDomain将字节数组转换为 类 Class的实例。

[Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", "")]
protected Java.Lang.Class? DefineClass (string? name, byte[]? b, int off, int len, Java.Security.ProtectionDomain? protectionDomain);
[<Android.Runtime.Register("defineClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", "")>]
member this.DefineClass : string * byte[] * int * int * Java.Security.ProtectionDomain -> Java.Lang.Class

参数

name
String

类的预期二进制名称;如果未知,则 null

b
Byte[]

构成类数据的字节。 位置通过的offoff+len-1字节应采用引用>Java&交易所定义的<有效类文件的格式;虚拟机规范</引用>。

off
Int32

类数据的起始偏移量b

len
Int32

类数据的长度

protectionDomain
ProtectionDomain

类的 ProtectionDomain

返回

Class 数据创建的 对象,可选 ProtectionDomain

属性

例外

如果 不包含有效的类,则 classRep 为 。

如果 offset 为 ,则为 ; length 如果 offset + length 大于 的 classRep长度,则为 。

如果 className 不等于 中包含的 classRep类的名称,则为 。

注解

使用可选的 ProtectionDomain将字节数组转换为 类 Class的实例。 如果域为 null,则默认域将分配给 文档 #defineClass(String, byte[], int, int)中指定的 类。 必须先解析类,然后才能使用该类。

包中定义的第一个类确定该包中定义的所有后续类必须包含的确切证书集。 类的证书集是从 java.security.CodeSource <tt>CodeSource</tt> 类的 内 ProtectionDomain 获取的。 添加到该包的任何类都必须包含相同的证书集, SecurityException 否则将引发 。 请注意,如果 namenull,则不执行此检查。 应始终传入要定义的类的二进制名称以及字节。 这可确保所定义的类确实是你认为它的类。

指定的 name 不能以“”java.开头,因为 “包java.* 中的所有类只能由引导类加载程序定义。 如果 name 不是 null,则它必须等于字节数组“”b指定的类的二进制名称,否则 NoClassDefFoundError <tt>NoClassDefFoundError</tt> 将引发 。

java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain)Java 文档。

此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。

适用于