Point me why i can't declare upper bonds for generics like this?:
public R computeMove(Map<K extends String,V extends Integer> c);
But can declare it like this:
public R computeMove(Map<K,V> c);
UPDATE
Interface:
public interface Strategy<K extends String,V extends Integer,T extends Map<K,V>, R extends GameFigures>{
public R computeMove(T c);
}
Interface Strategy realization:
Please, don't mind about return null
- it's only for example.
public class ProbabilityStrategy implements Strategy{
@Override
public GameFigures computeMove(Map c){
Collection<Integer> values=c.values();//<-- unchecked exception
Stream<Integer> stream=values.stream();//<-- unchecked exception
Optional userMaxFigureMoves=stream.max(Integer::compare);
return null;
}
}
Code works, but why there is unchecked exception if upper bounds for K and V declared in interface Strategy? So, Map
should be like Map<String, Integer>
If change the class code to:
public class ProbabilityStrategy implements Strategy{
@Override
public GameFigures computeMove(Map c){
Collection values=c.values();
Stream stream=values.stream();
Optional userMaxFigureMoves=stream.max(Integer::compare);//<-- compiler error
return null;
}
}
Code didn't compile and that's write, but why? According to interface Strategy, Map
should be as Map <String,Integer>
Can't understand why upper bounds for K and V didn't work for Map?