Why is the data type in java not an object?

I studied information about the java data type very early and found that they are primitive types. Since java is object oriented, but its data types are not. why is that so?

+3
source share
5 answers

It is more efficient to deal with primitive types than to make each variable a full-fledged object. The most common types (i.e., Int, char, float, etc.) are simple primitives. The remaining objects.

+3
source

, Java , Java . , . Wrapper java, "Integer" "Short" .. , . - , .

+3

Java .

- , .

, , , , , , , .

- , , , .

+2

.

  • / . Java , ... . . OO .

  • , .

Jesper ( ), OO . , , . , , .

, cannor . , :

  class MyInteger extends Integer /* a builtin numeric type */ {
      public ... add(...) { /* a different way of doing addition */ }
  }

? , .

In short, the penalty is either that OO numeric types (etc.) are slow and use more memory, that equivalent primitive Java types, or with which they are associated with restrictions that limit your ability to use OO type types.

+1
source

Performance and memory consumption are a good reason for primitive data types instead of using full-fledged objects.

0
source

All Articles