How do I convert Double[] to double[]?

后端 未结 8 1746
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 09:04

I\'m implementing an interface that has functionality similar to a table that can contain an types of objects. The interface specifies the following function:



        
8条回答
  •  -上瘾入骨i
    2020-11-28 09:36

    I don't have anything to add to the real question beyond what jjnguy and Eric Koslow said.

    But just a side note: You mention casting an Object array to a Double array. The following will NOT work:

    Object[] oa=new Object[3];
    oa[0]=new Double("1.0");
    oa[1]=new Double("2.0");
    oa[2]=new Double("3.0");
    Double[] da=(Double[])oa;
    

    The last line will throw a class cast exception. Even though every element in the array is indeed a Double, the array was created as an array of Objects, not an array of Doubles, so the cast is invalid.

提交回复
热议问题