Unpleasant casts for java 6