Seems to be ok. Other way would be to add a method getId() or something like that to Foo that would be proxied and could return getClass().