It's OK to do it if you can guarantee it will work. If there's any chance that
intf is pointing to an instance of another class,
you should check first (using
instanceof).
However, while casting is sometimes necessary, it can be an indication that the design is flawed. In the particular example you've given, if you want to treat the object as an
Example, then assign it to an
Example reference variable in the first place. In a more realistic example, there may well be a better way but it's impossible to say what that would be without knowing more about it.