我有两个类。
class Question
{
Hashtable<Integer, String> hs;
void populateHashTable();
//to populate hashtable during runtime.
}
class QuestionGetter
{
String s;
int x;
//I want string s to hold the value of the key x.
}
Question 类中的哈希表仅在运行时才会填充。 我正在使用 RMI 概念来运行两个相互通信并检索值的类。因此,在问题类中,我将添加多个问题及其问题编号,我想在输入问题键的 QuestionSetter 类中检索这些问题。
我该如何实现这个?
最佳答案
您的 QuestionGetter
类中必须有一个 Question
对象的引用:
class QuestionGetter{
Question question;
//constructors
public void add(String s, int x){
question.hs.put(x, s);
}
}
关于java - 在运行时从另一个类的哈希表中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26526029/