Home » questions » Why did java community decided to pass primitives by value and objects by reference?

Why did java community decided to pass primitives by value and objects by reference?

2006-08-13 11:58:00, Category: Programming & Design

Answers

  1. blainezee

    On 2006-08-13 12:09:22


    Just to confuse you. Ha no just kidding, its to increase the compatibilty so its the ideal cross-platform language. Just be careful while declaring objects using other objects and it doesn't pose much of a problem.
  2. anonymous

    On 2006-08-13 12:12:29


    My guess is that primatives are usually small and that user-defined objects can get very big. If you had to pass a huge object by value every time, you would eat up a terrible amount of memory for no good reason. And you would probably want to pass the large object by reference anyway for simplicity's sake. I guess passing primatives by reference could save work in some cases, but it seems prone to cause confusion as well. I'm only guessing, though. Good luck!
  3. seyyah

    On 2006-08-13 14:16:03


    if u have a variable that is a primitive and want to pass it to a function which will change it , you have to pass it by reference.If you ever want to send something to a function and be altered , u should pass by reference.It also helps performance mentioned above