move this function to the Java API. It is not type safe, should not be in core.