I use legacy library and need use cast Object to Collection.
For avoid exceptions I think to use instanceof.
So questions two:
1. If I use instanceof – need use try.. catch cast exception to avoid exceptions?
2. Does it hits performance?
Thanks.
I use legacy library and need use cast Object to Collection. For avoid exceptions
Share
If you use
instanceOfthen you do not needtry-catch(ClasscastException e).instanceOfis guaranteed to work, even withnulls.In today’s VMs, casting does not show any measurable performance hit. Rather if you find doing casting too often, then revisit your design.
NOTE:
instanceofdoes not work with Generics due to type erasure.