Ouch. I wonder if it wouldn't be better to write this entire class in Scala to avoid this sort of thing.