第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無法將值放入 HashMap<String,雙精度>

無法將值放入 HashMap<String,雙精度>

蝴蝶刀刀 2022-08-17 16:02:33
任何想法為什么我無法進(jìn)入這個(gè)HashMap?putpublic class UserImpl implements User{   HashMap<String, Double> videoRecords = new HashMap<>();   @Override   public void updateVideoRecord(String currentVideo, double seconds) {       videoRecords.put(currentVideo, seconds);   }}IntelliJ的調(diào)試器顯示兩者并傳遞值,但HashMap不會(huì)更新。以下是我用來檢測(cè)HashMap不接受這些值的內(nèi)容:currentVideosecondsvideoRecords@Overridepublic void updateVideoRecord(String currentVideo, double seconds) {      System.out.println(this.videoRecords);    this.videoRecords.put(currentVideo, seconds);    System.out.println(this.videoRecords);}有趣的是,如果我在此方法中初始化HashMap,則值將成功放入其中。
查看完整描述

1 回答

?
繁星點(diǎn)點(diǎn)滴滴

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}


查看完整回答
反對(duì) 回復(fù) 2022-08-17
  • 1 回答
  • 0 關(guān)注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)