Я всегда нахожу метод чтения что-то вроде прогулки по темному переулку. Вы опускаетесь немного и останавливаетесь, но если вы не считаете свои шаги, вы не знаете, насколько далеко вы находитесь. Seek дает решение путем повторного позиционирования, другой вариант - Tell, который возвращает позицию вдоль файла. Может быть, файл Python api может объединить чтение и поиск в read_from (position, bytes), чтобы упростить его - до этого вы должны прочитать эту страницу .
Если Вы имеете Map
с Enum
значения как ключи, то рассматриваете использование Java EnumMap
реализация:
https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/EnumMap.html
Здесь Вы также сделали, чтобы Baeldung отправил с некоторыми примерами о том, как использовать его:
Should be:
public class Mick {
private Map<MyEnum, OtherObj> myMap;
@Autowired
public void setMyMap(Map<MyEnum, OtherObj> myMap) {
this.myMap = myMap;
}
}
Have a look at http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-annotation-config
Updated
The problem is that according to the util schema, you cannot specify the key or value types. You can however to implement a MapFactoryBean of your own (just inherit from org.springframework.beans.factory.config.MapFactoryBean). One ceveat - notice that the generic definition (even thought erased in runtime) doesn't get in the way.
The
element has key-type, resp. value-type attributes, that represents the class of the keys, resp. the values. If you specify the fully qualified class of your enum in the key-type attribute, the keys are then parsed into that enum when creating the map.
Spring verifies during injection that the map's key and value types -as declared in the class containing the map- are assignment-compatible with the key and value types of the map bean. This is actually where you get the exception from.