关于Object[]数组强转成Integer[]类型的数组.
为什么不能由Object[]数组强转成Integer[]数组.
Object[] ins= {
new Integer(0),
new Integer(1),
new Integer(2),
new Integer(3),
};
Integer[] i = (Integer[]) ins;
执行时,系统报
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
如果改成下面的方式就可以了:
Object[] ins= {
new Integer(0),
new Integer(1),
new Integer(2),
new Integer(3),
};
Integer[] i = new Integer[ins.length];
for(int k = 0; k < ins.length; k++){
i[k] = Integer.parseInt(ins[k].toString());
System.out.println(i[k]);
}
为什么Object[]数组不能强转成Integer[]数组呢?
其实Object[]数组和Integer[]数组之前的关系并没有继承之间的关系,Integer[]的是Object的子类,并不是Object[]数组的之类.
Object[]数组是Object的之类.....
强转的话还是要一个个的对单独的元素进行强转.
关于Object[]数组强转成Integer[]类型的数组.的更多相关文章
- 关于Object数组强转成Integer数组的问题:Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
一.当把Object数组,强转的具体的Integer数组时,会报错. 代码如下: //数组强转报错演示 Object[] numbers = {1,2,3}; Integer[] ints = (In ...
- java.lang.ClassCastException: java.lang.Short cannot be cast to java.lang.String(Short类型无法强转成String类型)
有一行Java代码如下: String code1 = (String)qTable1.getValueAt(i, 0); 这是一个Java的图形界面获取表格中值的代码,其中qTable1.getVa ...
- dom对象转成jquery对象时候 变成数组 jquery转成dom时候 取数组第一个
- Hibernate 分页时 Long 无法转化成Integer类型 异常
转自:http://loquat.iteye.com/blog/818547 报错:java.lang.Long cannot be cast to java.lang.Integer Long ...
- Java集合转有类型的数组之toArray(T[] a)
在java变成中慎用强制类型转换,尽量使用类自带的转换函数或泛型.先看一行代码 错误方法: String[] array= (String[]) list.toArray(); 如果list中存放的是 ...
- VB.NET 数组的定义 动态使用 多维数组
我们都知道在全部程序设计语言中数组都是一个非常重要的概念,数组的作用是同意程序猿用同一个名称来引用多个变量,因此採用数组索引来区分这些变量.非常多情况下利用数组索引来设置一个循环,这样就能够高效地处理 ...
- Java 类型转换以及Object转成其他类型
Object转int int count=(int)map.get("count") int count=Integer.parseInt((String)map.get(&quo ...
- $.toJSON的用法或把数组转换成json类型
1. html页面全部代码 <html> <head> <title></title> <script src="../../S ...
- xamarin android如何将Java.Lang.Object类型转成C#类型
问题起源 其实这个标题也可以换一个更准确一点,因为我遇到的问题是: xamarin android中的Class继承了Java.Lang.Object ,将json序列化成c#类型时发现无法赋值,序列 ...
随机推荐
- 使用bootstrap的html文件转换成jsp…
问题:使用bootstrap的html文件转换成jsp时表单高度变窄 解决方法: 将jsp中html文档类型修改为<!DOCTYPE html> 问题即可解决. 也就是bootstrap只 ...
- Android问题-打开DelphiXE8与DelphiXE10编译空工程提示“[Exec Error] The command exited with code 1.”
问题情况:开发了半天的D2007代码,想测试一个安桌程序,发现新建空工程,提示失败. 提示如下 Exec Error] The command PATH C:\Program Files (x86)\ ...
- Spring Autowiring @Qualifier example
In Spring, @Qualifier means, which bean is qualify to autowired on a field. See following scenario : ...
- CodeForces 707A Brain's Photos (水题)
题意:给一张照片的像素,让你来确定是黑白的还是彩色的. 析:很简单么,如果有一种颜色不是黑白灰,那么就一定是彩色的. 代码如下: #pragma comment(linker, "/STAC ...
- C#中的where从句
C#中的where从句 2011-07-03 13:07OrphousV | 分类:C#/.NET | 浏览8443次 能解释一下下面两段代码中where的作用吗?using System;publi ...
- 让table 居于页面的正中间(上下左右均居中的方法)
? <table bgcolor="#jnkc" width="300" height="200" style="posit ...
- VS2015创建的Asp.net WebApi默认项目在CentOS7+Mono4.2.2+jexus5.8运行不起来的解决方案
主要原因是Web.config配置的问题. 修改成如下内容: <?xml version="1.0" encoding="utf-8"?> < ...
- BW知识点总结及面试要点
1. 如何理解数据仓库? 数据仓库 是 一个面向主题的,集成的,相对稳定的,反应历史变化的数据集合,用于支持管理决策. 2. OLAP 和 OLTP的基本概念 和 区别? Ol ...
- delphi 使用进度条查看浏览器状态
使用进度条查看浏览器状态 procedure TForm1.WebBrowser1ProgressChange(ASender: TObject; Progress, ProgressMax ...
- Cts框架解析(12)-ITargetPreparer
測试开启前的设备系统准备工作. 接口 /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Ap ...