Properly handle java refs in traits returning traits