没有错误
Object[] a = new String[]{"12","34","56"}; String[] b = (String[]) a;
没有错误
Object a = new String[]{"12","34","56"}; String[] b = (String[]) a;
运行时错误:ClassCastException
Object[] a = new Object[3]; a[0] = "12"; a[1] = "34"; a[2] = "56"; String[] b = (String[]) a;
运行时错误:ClassCastException
Object[] a = {"12","34","56"}; String[] b = (String[]) a;
当然,Object[]
如果String[]
它被创建为String[]
.
我的问题是为什么我们不能Object[]
转换到String[]
它创建的时间,Object[]
但它的所有成员都是字符串?是因为安全原因还是只是没有那么有用?