문제

Why can't I create an EnumMap like this:

EnumMap<FunkyTrolls, int> amountMap;

I want to count and save the number of trolls of each type. What is a good way of doing this?

도움이 되었습니까?

해결책

Just use Integer. Generics only work on objects, not on primitive types, but Java now has auto-boxing and -unboxing.

This should work:

Map<FunkyTrolls, Integer> amountMap = new EnumMap<FunkyTrolls, Integer>();
amountMap.put(FunkyTrolls.VERY_FUNKY_TROLL, 100);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top