I am working on a generic class and I want to use Class.cast() to do some casting to avoid those nasty unchecked cast warnings or the @SupressWarning annotation on the methods.
I think Class.cast() should be basically the same thing as casting directly. But like all reflection methods, it might not be the case. Does anyone know the exact different between them?
I recommend using Class.cast() over @SuppressWarnings where possible.
Don’t care about performance here. If you have performance issues, profile your application, and I would be very surprised if this turned out to be a hot spot.