I don't see your point at all. All you did was use a language feature java doesn't have, so it would take a few extra lines of code to implement the same thing in Java. That would be like me writing some java code which uses anonymous classes, then ask someone to write the same thing in c++. What does that prove? nothing.Now, just write a program in Java that produces the same output! See my point?
Well it's true that is how you would do it in c++ without destructors. In java, you would use the finally-without-catch idiom though.Now pretend C++ didn't have destructors. You'd basically be forced to resort to something like:
Code:void foo( void ) { A a; B b; C c; D d; try { a = new A(); b = new B(); c = new C(); d = new D(); } finally { if(a != null) a.cleanup(); if(b != null) b.cleanup(); if(c != null) c.cleanup(); if(d != null) d.cleanup(); } }