DEV Community

Discussion on: ELI5: Why cast to an interface?

Collapse
 
lluismf profile image
Lluís Josep Martínez

When you invoke a legacy method that returns Object or a very bad designed API. In these cases if you can't refactor the method (if it's an old version of Hibernate for instance) you have no other option than casting. I use to create wrappers over this kind of methods to generify them. Once they're generified you can remove all the casts.