0
我在下面的代碼中遇到了一些麻煩。我的問題是變量BGCLRFORPNLS
與變量c
的值不同。但它應該工作,因爲這個變量是一個參考。java設置變量
public static Color BGCLRFORPNLS = Color.BLACK;
private static void Initialze() {
List<Color> colors = new ArrayList<Color>();
colors.add(BGCLRFORPNLS);
Color c = colors.get(0);
JOptionPane.showMessageDialog(null, "hashcode of c: "+ c.hashCode());
JOptionPane.showMessageDialog(null, "hashcode of BGCLRFORPNLS: "+ BGCLRFORPNLS.hashCode());
c = Color.red;
JOptionPane.showMessageDialog(null, "color of c: "+ c.toString());
JOptionPane.showMessageDialog(null, "color of BGCLRFORPNLS: "+ BGCLRFORPNLS.toString());
}
jip我明白,但有沒有其他方式,所以它會工作?任何sugestions? – user744329 2012-03-12 09:23:51
@ user744329,如果要更改BGCLRFORPNLS的值,則必須執行類似BGCLRFORPNLS = Color.red的操作。 BGCLRFORPNLS不是最終的,因此您可以更改該值。但是,也許你應該擴展你真正想在這裏做的事情。 – ftr 2012-03-12 09:38:27