2017-07-14 16 views
0

リストからネストマップを作成しようとしています。以下、私は時間の誤差型不一致:Map <Object、Map <Object、List <ActorContents >>>からMap <Actor、Map <String、List <ActorContents >>>に変換できません。

型の不一致をコンパイル取得スニペットを使って:私は変更する場合に使用Map<Actor,Map<String,List<ActorContents>>>

Map<Actor, List<String>> actorTypeOfContents = typeofContentforActor(genres, genreId); 

      Map<Actor, Map<String, List<ActorContents>>> imageMap1=     
       actorContents.stream() 
         .collect(Collectors.groupingBy(e -> e.getActor(), Collectors.groupingBy(p -> Utility.find(actorTypeOfContents.get(p.getActor()), i -> StringUtils.contains(p.getName(), "_" + i + "_")) 
           ))); 

ユーティリティメソッドに Map<Object,Map<Object,List<ActorContents>>>から変換することはできませんすることなど

public static <T> T find(List<T> items, Predicate<T> matchFunction) { 
     for (T possibleMatch : items) { 
      if (matchFunction.test(possibleMatch)) { 
       return possibleMatch; 
      } 
     } 
     return null; 
    } 

を下回っています以下のコードエラーはなく、コードは実行されます。

List<String> actorNames =actorTypeOfContents.get(Actor.Genre1); 

Map<Actor, Map<String, List<ActorContents>>> imageMap1=     
       actorContents.stream() 
         .collect(Collectors.groupingBy(e -> e.getActor(), Collectors.groupingBy(p -> Utility.find(actorNames, i -> StringUtils.contains(p.getName(), "_" + i + "_")) 
           ))); 

あなたはあなたの助けが高く評価されて

Map<Actor, Map<String, List<ActorContents>>> imageMap1=     
       actorContents.stream() 
         .collect(Collectors.groupingBy(e -> e.getActor(), Collectors.groupingBy(p -> Utility.find(actorTypeOfContents.get(p.getActor()), i -> StringUtils.contains(p.getName(), "_" + i + "_")) 
           ))); 

+0

スタックトレースを表示します。私たちはあなたの心を読むことができません。 –

+0

これは、質問に記載されているコンパイル時エラーです。型不一致:Map >>をMap >>に変換できません。 –

+0

おそらく、2つのスニペットの間で異なるもの、つまり 'actorTypeOfContents.get(p.getActor()) 'に依存しているので、それが何かを知る必要があります。 – Radiodef

答えて

1

は、外側が同じ問題を持っているので、唯一のインナーマップMap<Object,List<ActorContents>>を考えることができますスニペットと間違っているかを把握するのに役立つ可能性があり。これを考慮してください:

Map<Object,List<ActorContents>> map = new HashMap<>(); 
map.put(1, Arrays.asList(new ActorContents())); 
map.put("one", Arrays.asList(new ActorContents())); 

ここで、異なるデータタイプの2つのキーを持つマップがあります。コンパイラに、キーの特定の型(Actor)を持つマップに変換するように依頼しています。コンパイラは整数または文字列をActorに変換する方法を知らない。

私の説明を読んだら、あなた自身で問題を理解できるはずだから、私は意図的にあなたのコードを参照していませんでした。 genericsチュートリアルも読んでみてください。

+0

私はあなたの説明を読んだが、私はそれが問題を解決するOPを助ける方法を知らない。あなたはジェネリック医薬品についていくつかの一般的なことを書きました。 – Holger

関連する問題