I was wondering about why some languages choose to implement numeric types (boolean, integers, floats, characters etc.) as classes/objects (eg. Kotlin) and some as primitive types (eg. Java). I am specifically considering interpreted languages rather than compiled languages.
Below are the differences that I was able to come up with:
As a class:
The type could then be extended, so that new classes could be treated as numeric types as well (i.e. being applicable to arithmetic operators).
No need for wrapper classes, as the type's relevant functionality could be encapsulated within the numeric type's class itself.
As a primitive:
- Less memory usage, as only the primive's value would be stored, rather than the extra bulk needed for an object.
What could any other reasons be?
Edit: This is not a duplicate of this question, as this question is purely about language-design, rather than what should be chosen for a specific practical and real-world problem.