显然,我无法将 Long 值存储在哈希表中。
请看下面的代码:
//create a hashtable of type <String, Long>
Hashtable <String, Long> universalTable = new Hashtable <String, Long> ();
universalTable.put("HEADS", new Long(0)); // this works fine
我在构造函数中传递了这个表DoFlip
:
DoFlip doFlip = new DoFlip(100000000, universalTable);
内部DoFlip
:
Hashtable table; // pointer to hash map
long iterations = 0; // number of iterations
DoFlip(long iterations, Hashtable table){
this.iterations = iterations;
this.table = table;
}
此类实现 Runnable。run()
方法如下——</p
>
public void run(){
while(this.iterations > 0){
// do some stuff
this.heads ++;
this.iterations --;
}
updateStats();
}
public void updateStats(){
Long nHeads = (Long)this.table.get("HEADS");
this.table.put("HEADS", nHeads); // ISSUE HERE
}
我收到以下警告/错误。看起来像一个警告,但我不想要这个。
Note: File.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
当我重新编译时:
File.java:92: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable
this.table.put("HEADS", nHeads);
^
1 warning
我不确定为什么会这样。首先,不需要输入 cast nHeads
。但我仍然这样做,但它不起作用。
注意:我一点也不擅长 Java。:/
谢谢您的帮助。