Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);//compile errorMap<Long, Double> map = new HashMap<Long, Double>();
map.put(11L, 22D);//correct提示:
Type mismatch: cannot convert from Double to Map<Long,Double>
怎么识别成Double去了

解决方案 »

  1.   

    你加D了,要放22D的话 你得引起来吧 貌似 “22D” 
      

  2.   


    put方法返回值是Double,又怎么可能转为Map<Long, Double>?
    编译报那么明显的错误,你还问?
      

  3.   

    你看这句代码
    map.put(11L, 22D);看它的提示消息,它的返回值是Double类型的
    Double java.util.Map.put(Long key, Double value)
    然后你的代码
    Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);
    左边是Map<Long, Double>类型,而你右边确是Double这个肯定会报:Type mismatch: cannot convert from Double to Map<Long,Double>
      

  4.   

    Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);
    赋值是取右边代码的最后一个返回值 不是new了就只能取new的
      

  5.   

    Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);//compile errorMap<Long, Double> map = new HashMap<Long, Double>(){put(11L, 22D);};
      

  6.   

    Map<Long, Double> map = new HashMap<Long, Double>(){{put(11L, 22D);}};