Avoid unnecessary casts when already of the right kind of object