0

Though we move ahead with Java versions, why are we maintaining support of primitives ( which are not objects consitituting to not making 100% OOP language ).

Wrapper classes around the primitives comes with support of auto boxing & unboxing as well.

Few main reasons I could think of are :

  • Though conversion happens automatically with (un)boxing support, behind the scenes it still does run .intValue() to get its associated primitive value to perform calculation & then stores back to its corresponding Integer object.

    Integer a=3,b=5;

// Below will do a.intValue()+b.intValue() & then store/display, if I am correct.

System.out.println(a+b); 

And also using wrapper class objects consumes heap space as opposed to performing arithematic operations using primitives on stack space.

  • I read something stating : its for support of some Enumeration classes as a backward compatibility reason?

Is above listed reasons not leading to non-elimination / making deprecated on primitives usage?.

user3584056
  • 184
  • 1
  • 6
  • Are you suggesting we get rid of primatives? – Anubian Noob Jun 18 '14 at 14:52
  • Actually not, would like to know exact set of reasons on retaining them. I did saw the thread prior to asking this, since it din't made me feel conclusinve on reason part. – user3584056 Jun 18 '14 at 14:59
  • 2
    Backward compatibility is a good enough reason. Can you imagine what would happen if they took the primitives away--how many hundreds of thousands of man-hours would be spent changing all the existing programs to work with the new compiler? Nobody would upgrade. It's a fact of life that programming languages get stuck with features the designers wish they could get rid of, like Java being stuck with raw `List` types. But there wouldn't even be any practical value in getting rid of primitives. – ajb Jun 18 '14 at 15:11

0 Answers0