| I've heard theorists say exactly this a number of times before. The reason Java isn't a 'pure' object-oriented language is simply performance. Suppose everything - even every int - is heap-allocated. You now need a very sophisticated JIT compiler (as in, better than any we have today), or it's going to run dog slow. Having a huge number of needless allocations happening at every step is going to: 1. Slow things down by doing vastly more heap allocations that you otherwise would (even with Java's ultra-fast allocations) 2. Slow things down by doing violence to your code's locality and cache behaviour, because your ints no longer live in the stack 3. Slow things down by doing violence to your code's locality and cache behaviour, because Java objects are bloated compare to raw ints 4. Slow things down by hugely increasing garbage-collection pressure If Gosling had taken that route, we wouldn't be talking about Java today. |
Most dynamic language implementations (JavaScript, Lisp, Smalltalk, even Ruby) use a tagged pointer representation allowing integers (and sometimes floats) to be encoded directly in the reference, avoiding heap allocation in this common case.
Another alternate model is to pass the type of a value separately from the value itself, and allow the value to be of variable size.
Java simply made the wrong tradeoff, and while it wasn't fully apparent at the time, there's no good defense of that decision today.