Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Default virtual was among the dumber design mistakes in Java, but it has lots of competition.


Why? The JVM has complete knowledge over the entire code base at runtime. It knows which methods require virtual function calls and which ones are just regular function calls. If nothing extends the class, then there will be no virtual functions in the entire class. If something extends the class but it does not override any methods then there again will be no virtual functions. If a class overrides a single method, only that method is going to be a virtual function.


See my reply to the GP. Default virtual is the only thing that makes sense given how the JVM works.


You understand the JVM was designed at the same time as the language? It could work any way they liked. And does.


Sure, but if you have the same preferences (throughout over latency), you’ll find that there are no performance benefits to be gained from non-virtual functions in any JITed language. The “final” keyword is just there for documentation.


Virtual or not isn't about performance, it is about system architecture. Virtual is structurally about implementation. Exactly to the degree that the public interface matches the inheritance interface, the abstraction is a failure.

At least, if you are being object-oriented, which Java tries to force on you. Of course, you are free to violate that expectation, and sometimes must since Java offers no other means of organization; so if you do, more power to you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: