The Frequency class has no generic types, but creates an internal TreeMap, with keys with the type `Comparator<?>`. Then whenever you add or get values from the TreeMap, it will throw CCE if you pass a key value with a different type from the others stored in the map.
And even a simpler example without Math classes to help outlining the issue.
It is not clear how we could compare the key type to the given v value. Checking if the map is not empty, and then checking the type of the first key doesn't sound very elegant (and not sure if it would be a valid solution).
A better solution could be to add generics to the class, breaking the current contract (i.e. not allowing three types, boxing to longs, etc), but on the bright side, it won't use CCE as a normal workflow, nor need suppress warnings annotations any more.