4 ms·
You cannot write a generic swap in Java. You can in C++.
by qznc 9y ago
You cannot write a generic swap in Java. You can in C++.
- syrrim 9y agoWhy not? Java support reflection, so you can - at runtime - enumerate all the properties of an object. From there, you would assign each property from a to b. The only thing stopping this is that not all properties will be public, but this seems like a pedantic hangup to me. They are functionally equivalent.
- adrianmonk 9y agoSubclasses and final fields make this impossible in the general case.