a clean way passing object arguments

Discussions

EJB design: a clean way passing object arguments

  1. a clean way passing object arguments (4 messages)

    As we all know,java has two parameter-passing methods while call a function:
    1.to primitive type,it use value
    2.to object, it use reference.
    So here is the question:
    when I use a method in a class provided by others,and this function need pass some objects as auguments.So there is possibility that after calling this function,the object's value has been changed.Is there any clean method to avoid this and guarantee the object is same before and after calling the function.
    I know one way is:everytime before I use a function,I clone an object.But the way is too tedious and not fesible in reality.

    Threaded Messages (4)

  2. a clean way passing object arguments[ Go to top ]

    All objects in EJB are passed by copy so you need to take this into consideration in your application. Objects are not passed by reference in EJB.

    Dave Wolf
    Internet Applications Division
    Sybase
  3. a clean way passing object arguments[ Go to top ]

    if you are using weblogic, objects can also be passed by value and this is the default setting in the deployment descriptor.
  4. a clean way passing object arguments[ Go to top ]

    By copy and by value are actually the same thing. Although BEA does have a pass by reference option, the EJB spec requires the objects either be passed by copy, or act as if they were. So there are really very few places where the pass by reference helps.

    Dave Wolf
    Internet Applications Division
    Sybase
  5. a clean way passing object arguments[ Go to top ]

    Thanks Dave.
    But there's also two issues:
    1.in real application,I couldn't code every class in ejb,there must be a lot of java classes and bean classes.
    2.there are a lot of legacy classes,including jdk classes which you must trust.But fortunately most object arguments jdk used are String type which is totally different from the other object.