Smart `cast` operation
Closed this issue · 0 comments
dmlloyd commented
People are frequently tripping over casting, because primitive casts, object casts, and boxing/unboxing are all done in different ways. Provide a smart cast
operation with the following support:
- Cast primitives to primtives as per
convertPrimitive
- Cast objects to objects as per
checkCast
And optionally:
- Cast primitives to primitive box objects by doing primitive-to-primitive conversion (if necessary) followed by
BoxType.valueOf(...)
- Cast primitive box objects to primitives by doing
BoxType.xxxValue()
followed by primitive-to-primitive conversion (if necessary) - Cast box objects to box objects by unboxing, converting, and then re-boxing
Since checkCast
allows a String
argument, primitive types and box types would need to be recognized by name.