1 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果您可以添加您的運(yùn)行器代碼或至少您的方法,那將有所幫助。無論如何,我試圖重現(xiàn)您的問題,但它似乎沒有任何問題或任何東西。main()
在這里,我像你一樣使用了相同的類實(shí)現(xiàn),我只是添加了一個(gè)get方法,將映射返回到該方法:UserImplmain
import java.util.*;
import java.util.HashMap;
public class UserImpl implements User {
HashMap<String, Double> videoRecords = new HashMap<>();
@Override
public void updateVideoRecord(String currentVideo, double seconds) {
videoRecords.put(currentVideo, seconds);
}
public HashMap<String, Double> getRecords() {
return videoRecords;
}
}
它從這個(gè)“Mock”接口實(shí)現(xiàn),因?yàn)樵谀膶?shí)現(xiàn)中,您正在重寫方法。updateVideoRecord()
顯然,在我創(chuàng)建類的對(duì)象中,將一個(gè)新條目放入HashMap并在放置之前和之后打印。MainUserImpl
import java.util.*;
public class Main {
public static void main(String[] args) {
UserImpl userImpl = new UserImpl();
HashMap<String, Double> records = userImpl.getRecords();
System.out.println("The size of the map is " + records.size());
System.out.println("Initial Mappings are: " + records);
userImpl.updateVideoRecord("theCurrentVideo", 360);
System.out.println("The size of the map is " + records.size());
System.out.println("Initial Mappings are: " + records);
}
}
最后,在這里您可以看到輸出看起來完全符合預(yù)期,因此我沒有看到您的問題。因此,如果你能更詳細(xì)地闡述你的問題,也許我可以提供更好的幫助。如果沒有,那么我希望這有助于您解決問題。
kareem@Kareems-MBP:Desktop$ javac Main.java
kareem@Kareems-MBP:Desktop$ java Main
The size of the map is 0
Initial Mappings are: {}
The size of the map is 1
Initial Mappings are: {theCurrentVideo=360.0}
添加回答
舉報(bào)