If you implement an interface in Java, there is nothing to prevent the caller from looking at what concrete implementation you have supplied, casting to that class and calling methods that are not in the interface. I believe this is called "malicious downcasting".

A way to prevent this is to create a wrapper that only has the interface's methods and does not expose the implementation instance to which it delegates. Short of reflection to private variables you should be safe.

Is there a way to automatically create these kind of wrappers (at run-time, not using a code creation wizard in the IDE, because that still creates a source file that needs to be maintained) ?