java array.getlength_Java ArrayHelper.getLength方法代码示例

import javaemul.internal.ArrayHelper; //导入方法依赖的package包/类

public static void arraycopy(Object src, int srcOfs, Object dest, int destOfs, int len) {

checkNotNull(src, "src");

checkNotNull(dest, "dest");

// TODO: right now, all checks are disabled but could be reactivated

// when appropriate support is available

// Class> srcType = src.getClass();

// Class> destType = dest.getClass();

// TODO: support isArray() as a macro

// checkArrayType(srcType.isArray(), "srcType is not an array");

// checkArrayType(destType.isArray(), "destType is not an array");

// TODO: support getComponentType() as a macro

// Class> srcComp = srcType.getComponentType();

// Class> destComp = destType.getComponentType();

// checkArrayType(arrayTypeMatch(srcComp, destComp), "Array types don't

// match");

int srclen = ArrayHelper.getLength(src);

int destlen = ArrayHelper.getLength(dest);

if (srcOfs < 0 || destOfs < 0 || len < 0 || srcOfs + len > srclen || destOfs + len > destlen) {

throw new IndexOutOfBoundsException();

}

/*

* If the arrays are not references or if they are exactly the same

* type, we can copy them in native code for speed. Otherwise, we have

* to copy them in Java so we get appropriate errors.

*/

// if ((!srcComp.isPrimitive() || srcComp.isArray()) &&

// !srcType.equals(destType)) {

// // copy in Java to make sure we get ArrayStoreExceptions if the

// // values

// // aren't compatible

// Object[] srcArray = (Object[]) src;

// Object[] destArray = (Object[]) dest;

// if (src == dest && srcOfs < destOfs) {

// // TODO(jat): how does backward copies handle failures in the

// // middle?

// // copy backwards to avoid destructive copies

// srcOfs += len;

// for (int destEnd = destOfs + len; destEnd-- > destOfs;) {

// destArray[destEnd] = srcArray[--srcOfs];

// }

// } else {

// for (int destEnd = destOfs + len; destOfs < destEnd;) {

// destArray[destOfs++] = srcArray[srcOfs++];

// }

// }

// } else

if (len > 0) {

ArrayHelper.copy(src, srcOfs, dest, destOfs, len);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值