????Java??????????????
???????????? ???????[ 2012/11/13 11:38:36 ] ????????
?????塢????????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?????????????????????????????鷵?????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11