?????塢????????5#???????????????

??????????????????????????????????????С????????????????????????????????????????????????????????????????????

import java.awt.Dimension;
/*** Example class. The height and width values should never * be negative. */ public class Example{
static final public int TOTAL_VALUES = 10;
private Dimension[] d = new Dimension[TOTAL_VALUES];
public Example (){
}
/*** Set height and width. Both height and width must be nonnegative * or an exception will be thrown. */ public synchronized void setValues (int index?? int height?? int width) throws IllegalArgumentException{
if (height < 0 || width < 0) throw new IllegalArgumentException();
if (d[index] == null) d[index] = new Dimension(); d[index].height = height;
d[index].width = width;
}
public synchronized Dimension[] getValues() throws CloneNotSupportedException{
return (Dimension[])d.clone();
}
}

?????????????????getValues()????????????????飬????п???????а?????Dimension????????????????????????????????????????????Dimension????????????????????????????????(???Dimension????)???????????getValues()????e汾???

public synchronized Dimension[] getValues() throws CloneNotSupportedException{ Dimension[] copy = (Dimension[])d.clone();
for (int i = 0;
i < copy.length; ++i){
// NOTE: Dimension isn’t cloneable. if (d != null) copy[i] = new Dimension (d[i].height?? d[i].width);
}
return copy;
}

???????????????????????????????????????????????????int??float?????????int??????????????????????????

public void store (int[] data) throws CloneNotSupportedException{ this.data = (int[])data.clone(); // OK }

????????int??????????????Щ??Java???int????????飬??????int??????????????????????????????飺????????? int[]????????int[][]????????????????????getValues()????????汾??????????????????????????????????????????int??????????????????????????

public void wrongStore (int[][] data) throws CloneNotSupportedException{
this.data = (int[][])data.clone();
// Not OK!
}
public void rightStore (int[][] data){
// OK!
this.data = (int[][])data.clone();
for (int i = 0;
i < data.length;
++i){ if (data != null)
this.data[i] = (int[])data[i].clone();
}
}

????????????????6#?????new ????????????null

????Java???????????????new????????????null???????????????

Integer i = new Integer (400); if (i == null) throw new NullPointerException();

??????鵱??????????????????if??throw?????д????????????????????????????????????????и?????

????C/C++?????????дjava?????????????????????????????C??malloc()???????????????????????????????????? C++??new???????????????????????????????????????????(????????????????????????????????new??????????null)????java ?У?new ?????????????null???????????null?????????????????????????????鷵?????????????