4 ms·
You are supposed to use generics: Iterator<Map.Entry<UUID, ExpiringEntityPlayer>> ghostI = hashtableNPCs.entrySet().iterator(); while (ghostI.hasNext()
by cesarb 6y ago
You are supposed to use generics:
Iterator<Map.Entry<UUID, ExpiringEntityPlayer>> ghostI = hashtableNPCs.entrySet().iterator();
while (ghostI.hasNext()) {
ExpiringEntityPlayer expiringEntityPlayer = ghostI.next().getValue();
}
However, it's a sham. The generic types are stripped at runtime. The compiler will prevent you from putting values in the map that are not an ExpiringEntityPlayer, as long as you are diligent in using generics everywhere, and don't fall in the few traps where the wrong type can slip by without a warning, but you can still be hit by a ClassCastException at runtime if you're not careful.
- tpxl 6y ago> but you can still be hit by a ClassCastException at runtime if you're not careful. While it is true the generics are more or less syntactic sugar, I have never seen a ClassCastException due to this in all my years.
- twic 6y agoThis is exactly like saying all types in C or C++ are a sham because you can cast a typed pointer to a void pointer.