Return by Reference/Return by Value

Okay. I am suppose to create this accessor method that is not suppose to return by reference so as to protect the private variables.
Firstly, I suppose for primitive data type I can :
public int rtnInt() {
int i = 0;
int j;
int j = i;//Primitive type creates new memory for variable
return j; }
Right? Or can I just return i? Will returning i result as a reference to i?
Secondly, I am stumped on reference data type, example if I have :
public String rtnstr() {
String a = "a"
String b;
String b = a; //Can't do this right, it will just reference to the location of a?
return b;
So how do you actually copy a new a to and assign it to b? Oh ya, am I right to say arraycopy copies a new array and I don't have to worry about referencing?

Noobie1987 wrote:
Eh? So you mean to say I can just return or pass any variables, reference or primitive type, without fear of the original being modified?"Returning variables" does not pertain here, since when you return from a method, the variables are popped from from the stack and cease to exist. When you pass a variable to a method, a copy of that variable's value is used within the method. Changing the variable within the method does not affect the variable outside the method. Ever.
But I thought 2 variables referencing the same memory location will affect each other if a change is made. AKA...
String[] str = {0};
String[] abc = str;
abc[0] = 1;
So str[0] will become 1?First, that example won't compile. Second, there is no passing of anything; just variable assignment.
It is important to understand that variables do not contain objects. Read this: [http://www.javaranch.com/campfire/StoryPassBy.jsp]
~

Similar Messages

  • Explicit return or Reference

    Hi everyone,
    I have a utility method to which i pass a List object. Within the utility method i update the value of each object in the list based upon some information passed in another parameter to the method.
    What i am wondering is if i should now return the list as the return value from the method, or whether i let clients of the method assume that the value of the list they passed as a parameter into the method is automatically updated ( when objects are passed it is by reference and the value of the object can be altered within the destination method )
    e.g should the method resemble
    public void doSomthing( java.util.List aList, int aValue )
    Iterator listIterator = aList.iterator();
    while( listIterator.hasNext() )
    MyObject anObject = ( MyObject ) listIterator.next();
    anObject.setA( aValue );
    or should it be
    public List doSomthing( java.util.List aList, int aValue )
    Iterator listIterator = aList.iterator();
    while( listIterator.hasNext() )
    MyObject anObject = ( MyObject ) listIterator.next();
    anObject.setA( aValue );
    return aList;
    All help appreciated.......

    but for convenience you could return the 1st parameter.
    As Component::Container.add(Component) does in AWT.

  • Ctrl val get reference returns refnum of zero

    I am using 'ctrl val get' in a vi.  The value it is getting is a cluster of references, the references are being returned all with a value of zero.  Is there a prohibition against using 'ctrl val get' with references?
    -Regards
    eximo
    UofL Bioengineering M.S.
    Neuronetrix
    "I had rather be right than be president" -Henry Clay
    Solved!
    Go to Solution.
    Attachments:
    ctrl val get references returns refnum 0.PNG ‏11 KB

    Yes the error is an invalid object error 1055
    I have posted the error screen shot.  It refers to the property node but if I probe the cluster it shows all refnums => 0 are zero
    (screen shot has the same name, but it's updated from the last one)
    -Regards
    eximo
    UofL Bioengineering M.S.
    Neuronetrix
    "I had rather be right than be president" -Henry Clay
    Attachments:
    ctrl val get references returns refnum 0.PNG ‏78 KB

  • Inclusive Free Goods Return with Reference

    Hi Gurus!
    Could you help me with my question below
    We are tring to create a sales order return with reference to a billing document. This billing document has two items where one is a standard item and the other is a inclusive free goods item.
    Example:
    1            AAA

    Hi
    When you have creating the sales order  with reference to billing document the items will be copied into the return order without any changes
    You can check the controls in the copy control VTAF
    Regards
    Damu

  • ORDERS05 - Create a Return with reference to a Sales Order

    Hi all,
    I'm trying to create a return with reference to a sales order via IDOC ORDERS05. I'm indicating referenced Sales Order number into segment E1EDK02; indicating qualifier (QUALFR = 002) and Sales order number (BELNR). By this way, I create a Customer Return but without reference.
    Which fields or segment have to be filled in order to create it correctly?
    Thanks
    Marí

    Correct...
    You need something like:
    *Get the pricing cond number.
    select single knumv from vbak into cond
      where vbeln = '0000080347'.
    if sy-subrc = 0.
    Get the pricing record which are by line item.
      select * from konv into table konv_tbl where knumv = cond.
    Loop thru them one line at a time.
      loop at konv_tbl.
       bapi_cond-itm_number = '000010'.
        bapi_cond-cond_st_no = konv_tbl-stunr.
        bapi_cond-cond_count = konv_tbl-zaehk.
    CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
      EXPORTING
        RETURN_HEADER_IN               = bapi_hdr
       BUSINESS_OBJECT               = 'BUS2102'
        CONVERT                        = 'X'
      IMPORTING
        SALESDOCUMENT                 = bapi_salesdoc
       RETURN                        = BAPI_RET
      TABLES
        RETURN                        = bapi_ret_tbl
        RETURN_ITEMS_IN                = bapi_itm
        RETURN_ITEMS_INX               = bapi_itm_out
        RETURN_PARTNERS                = bapi_prtnr
        RETURN_SCHEDULES_IN            = bapi_schd_lin
        RETURN_CONDITIONS_IN           = bapi_cond.  "pricing
      ORDER_TEXT                    = bapi_text.

  • Create return with reference to original sales order - pricing

    Hi
    I am using the function SD_SALESDOCUMENT_CREATE to create a return order with reference to the original sales order.
    All the information from the original sales order (including pricing conditions) I've read with the function BAPISDORDER_GETDETAILEDLIST.
    The problem : the pricing conditions. I need to copy the conditions from the original order and it is not working correctly.
    Any ideas?
    Thanks.
    Anca

    Correct...
    You need something like:
    *Get the pricing cond number.
    select single knumv from vbak into cond
      where vbeln = '0000080347'.
    if sy-subrc = 0.
    Get the pricing record which are by line item.
      select * from konv into table konv_tbl where knumv = cond.
    Loop thru them one line at a time.
      loop at konv_tbl.
       bapi_cond-itm_number = '000010'.
        bapi_cond-cond_st_no = konv_tbl-stunr.
        bapi_cond-cond_count = konv_tbl-zaehk.
    CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
      EXPORTING
        RETURN_HEADER_IN               = bapi_hdr
       BUSINESS_OBJECT               = 'BUS2102'
        CONVERT                        = 'X'
      IMPORTING
        SALESDOCUMENT                 = bapi_salesdoc
       RETURN                        = BAPI_RET
      TABLES
        RETURN                        = bapi_ret_tbl
        RETURN_ITEMS_IN                = bapi_itm
        RETURN_ITEMS_INX               = bapi_itm_out
        RETURN_PARTNERS                = bapi_prtnr
        RETURN_SCHEDULES_IN            = bapi_schd_lin
        RETURN_CONDITIONS_IN           = bapi_cond.  "pricing
      ORDER_TEXT                    = bapi_text.

  • Problem in return order not copied assessable value

    Hi Colleagues,
    Here, the project was implemented 10 years back and till now the processes in system were working fine. But, raised a concern on returns.
    During billing assessable value is captured at say 100/- But, if the material is being returned into plant after 1 year or so.....then during goods returns, assessable value at current prices ..say 95/-.
    Now the client want to return the stock at same price during original goods issue i.e at 100/- only. Even if goods return 100/- ...then where do difference (5/-) will be posted.
    I think it is not possible in standard process in system. To take up this activity with system modification, can we utilize userexits in SD module? If so, can anybody please tell...which include can we consider to do this.
    regards
    ajit

    Is this TAXINN or TAXINJ procedure we are using.
    if this is TAXINN
    please check for the condition record that has benn maintained for the Excise condition.
    Regards
    Virandra Sharda
    9427630630

  • Why is the returned internal table contains same values?

    Hi all,
    I got a bapi that returned an internal table type MARC.
    For testing in R/3, the internal table returns 3 material no. with different values,
    but in vb.net, it returns 3 entries with same values,
    (I've passed the internal table as ByRef in the vb)
    what's wrong are there?
    Thanks.

    Please post your test code.

  • UPDATE ... RETURNING does not return new value

    Hi all,
    I've created the following objects in Oracle DB 10.2.0.3.0:
    CREATE TABLE TAB1
         ID          NUMBER          PRIMARY KEY,
         EDITED_AT     DATE,
         VALUE          VARCHAR2(64)
    CREATE SEQUENCE S_TAB1
         INCREMENT BY 1
         START WITH 1;
    CREATE TRIGGER T_TAB1_BIE
    BEFORE INSERT OR UPDATE ON TAB1
    FOR EACH ROW
    BEGIN
         IF INSERTING THEN
              SELECT S_TAB1.NEXTVAL INTO :NEW.ID FROM DUAL;
         END IF;
         :NEW.EDITED_AT := SYSDATE;
    END;
    /Then I tried to do the following in SQL Plus:
    SQL> insert into tab1(value) values('ddd');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select * from tab1;
            ID EDITED_AT           VALUE
             1 27.03.2008 17:01:24 ddd
    SQL>
    SQL> declare dt date; val varchar2(64);
      2  begin update tab1 set value = 'ddd' where id = 1 returning edited_at, value into dt, val;
      3  dbms_output.put_line('txt = ' || dt || ', ' || val);
      4  end;
      5  /
    txt = 27.03.2008 17:01:24, ddd
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from tab1;
            ID EDITED_AT           VALUE
             1 27.03.2008 17:02:12 ddd
    SQL>As it can be seen Returning clause of an Update statement does not return a new date, i.e. 27.03.2008 17:02:12, that was updated by the trigger, it returns an old one - 27.03.2008 17:01:24. Please advise me why Database returns an old value? I do believe that UPDATE ... RETURNING ... statement should return new, generated by the trigger, value.
    Thanks in advance.
    Regards,
    Yerzhan.

    you need to explicitly include the column in your UPDATE statement SET clause that you expect to return the result you want it to be. here's what i think what happened even though you have a trigger the first statement that was processed was your update statement. at the time of the update it has to return the current values to the returning clause that is the values on the table. now comes next the trigger which gives edited_at column a new value. when the trigger got fired the process don't return anymore to the UPDATE RETURNING statement. it's like each sequence of codes does not executes in parallel.
      SQL> CREATE TABLE TAB_1
        2  (
        3   ID  NUMBER  PRIMARY KEY,
        4   EDITED_AT DATE,
        5   VALUE  VARCHAR2(64)
        6  );
      Table created.
      SQL> CREATE SEQUENCE S_TAB1
        2   INCREMENT BY 1
        3   START WITH 1;
      Sequence created.
      SQL> CREATE TRIGGER T_TAB1_BIE
        2  BEFORE INSERT OR UPDATE ON TAB_1
        3  FOR EACH ROW
        4  BEGIN
        5   IF INSERTING THEN
        6    SELECT S_TAB1.NEXTVAL INTO :NEW.ID FROM DUAL;
        7   END IF;
        8   :NEW.EDITED_AT := SYSDATE;
        9  END;
       10  /
      Trigger created.
      SQL> insert into tab_1(value) values('ddd');
      1 row created.
      SQL> commit;
      SQL> select * from tab_1;
              ID EDITED_AT            VALUE
               1 28-mar-2008 10:31:18 ddd
      SQL> declare dt date; val varchar2(64);
        2  begin update tab_1 set value = 'ddd', edited_at = sysdate
        3        where id = 1 returning edited_at, value into dt, val;
        4  dbms_output.put_line('txt = ' || dt || ', ' || val);
        5  end;
        6  /
      txt = 28-mar-2008 10:32:39, ddd
      PL/SQL procedure successfully completed.
      SQL> select * from tab_1;
              ID EDITED_AT            VALUE
               1 28-mar-2008 10:32:39 ddd
      SQL>

  • Returning remote reference

    Hi everybody, I'm having quite some trouble with RMI, everytime I try to return a reference to a Remote object on my server I get the usual "unmarshalling return" error. Problem is that my Object I'm trying to return actually implements the Remote interface:
    public interface Bank extends Remote {
         public Account create_account (String name) throws BankException, RemoteException;
    };the Implementation looks like this:
    public class BankImpl implements Bank {
         public Account create_account (String name) throws BankException {
              Account k = new AccountImpl(name);
              return k;
    }Again the interface and Implementation:
    public interface Account extends Remote {
        public Account(String name);
    public class AccountImpl implements Account, Remote  {
         private String name = null;
         AccountImpl(String name){
              this.name = name;
    };I'm quite stuck here, is there something I'm missing??? I thought that function whose return type is some implementation of the Remote interface will automatically get passed by reference with an automatically generated stub.

    It seems to me that having to actually extend the UnicastRemoteObject is quite a limitation.You don't have to. I gave you that as the simplest solution. If you don't extend UnicastRemoteObject, you have to export the object yourself with UnicastRemoteObject.exportObject(). Use the overload where you specify a port number, even if it's only zero (= any).
    And somehow I'm unable to cast the generated Proxies to my Interfaces.
    Actually I can only let my extend the "Remote" interface in my interfaces and them implement my Account interface and extend "UnicastRemoteObject" in the implementations and still it won't work.What happens? You'll have to show us the code ... btw is there something missing back there?
    Still think I'm missing something...For sure. RMI works.

  • Java returning the reference of the current class.

    Hi,
    I want to write a method in Java to return the reference of the current class in a static manner i.e, without instantiating the class. Please help as to how to go about it.
    Thanks.

    Come on, at least point out where the guy is wrong.
    user563329 wrote:
    I want to write a method in Java to return the reference of the current class in a static manner i.e, without instantiating the class.There is no concept of a "current class" but I guess you meant "the class where the code is defined that the current thread is running now".
    However, that means that class (code) has been instantiated so your question makes no sense.
    If you want the class of the "current running code" use Object#getClass().
    You can reference a class without instantiating it but it will still be loaded. For example:
    public class TestInit {
        public static void main(String[] args) {
            System.out.println(Init.class.getSimpleName());
    class Init {
        static { System.out.println("Init init"); }
    // running it with java -verbose:class show Init is loaded but the static initializer is not run
    // loading lots of class ending with
    [Loaded TestInit from file:/C:/Projects/Dump2/Output/]
    [Loaded java.lang.Void from shared objects file]
    [Loaded Init from file:/C:/Projects/Dump2/Output/]
    Init
    [Loaded java.lang.Shutdown from shared objects file]
    [Loaded java.lang.Shutdown$Lock from shared objects file]

  • Return goods: sales return

    Hi sap gurus,
    If the goods are returned back, what happens to the returned goods.
    What is the diff b/w Subsequent delivery free of charge and free of charge delivery

    When the goods are returned back , it first goes to the Block/restricted stock.
    The quality assurance department will varify it and if they certify as 'OK', then again a document is created with a different movement type to include it in the un-restricted stock.
    In the process, we have to create a Return order (you have to put a order reason,why this has taken place ), which can be created either with reference to the Sales order or Billing document. Ofcourse it can be created without any reference also.
    With reference to the Return order, a Return delivery is created and a Put away & PGR for the same.
    Then, we have to issue a Credit memo for the return and **it is created with reference to the Return order**.
    Before creating a Credit memo , you have to remove the "billing block" from the Return order.
    your 2nd question
    When you send a Demo material to your customer, you do not charge for it. It is for demonstration purpose , so no commercial value is associated.
    To process this type of material, you create an order with Order type FD.  This is called "Free of charge Delivery".
    Another scenario,
    You had sent some quantity of material say M1 to your cutomer.
    Customer has paid for those quantity. Now, customer has returned suppose one unit due to damage. I want to replace this one unit by a fresh one. So, now I will send a fresh piece as replacement which is free of charge.
    That means , I am sending subsequently one more unit/quantity which is now free of charge. This is processed with order type SDF and called "Subsequent delivery Free of charge".
    The most important difference between  "FD" (Free of charge delivery) and "SDF"(Subsequent delivery free of charge) is that FD does not require any reference but SDF always requires a preceding document.

  • Development of Form for Returnable and Non-returnable material Gate pass

    Dear Experts,
    I am working with an Indian client impementing SAP PM. I need help in developing a form for Returnable and Non Returnable Gatepass. Requirements are below;
    RGP/NRGP should be made for all materials going out of the factory, irrespective of it being coded or not
    It should be plant specific
    It should have reference to material movement document for tracking purpose
    It should have details of vendor, transport company, vehicle number, permits if required, etc
    A Z report should give details of all RGP/NRGP based on material document number and date
    Please guide me based on your experience.
    Thanks,
    Boby

    Boby,
    This can be met. But before developing this, have you implemented the refurbishment process of PM module? This will really help in tracking the equipment and also for the development of RGP/NRGP.
    First you have to create a form for the gate pass  and have to create an enhancement in MIGO for triggering the RGP/NRGP, else you can also create a separate Z transaction code for printing the Gate pass. You will get all the fields like vendor, material, QTY, movement type from the MIGO GI document. 
    For the gate pass the MIGO document will be the reference all the times, you can also develop a Z report for the records for the gate pass.
    Regards,
    Praveen

  • Which better performance? return "blah" or return "blah".clone()?

    Is there a performance diff. between returning a String created inside my method and returning a clone of it?

    If applying this question to return x versus return x.clone(), where x is an object belonging to a class which supports cloning, the obvious answer is the former.
    Depending on the cloning technique used (deep or shallow), cloning will create 1...n extra objects prior to returning from the clone() method. Regardless of the technique, you will be creating at least one new object, whereas the return statement simply returns the value.

  • Reg:"No result returned or xml returned in the result contains an Error

    Dear All,
    After adding a query to VC storyboard and than trying to use the option define/test query for this query element, I am facing the below error on pressing the execute button.
    "No result returned or xml returned in the result contains an error"
    Query is working fine and giving the desired output in BW system.
    How can i resolve my problem?
    Regards,
    Hemalatha J
    Edited by: hema latha on Nov 19, 2009 3:21 PM

    Hi Hemalatha,
    this can have several reasons, usually there are variables in the query that aren't filled correctly in the "specify filter" box.
    One thing you could do is to personalize all variables in the query and then try to fill one after another in the "specify filter" box.
    If you don't get values after you have filled a specific one of them, then this one is passed incorrectly.
    Best wishes
    Markus

Maybe you are looking for

  • SQ03, user group removed after release upgrade from 4.6C to ECC6

    Dear All, I have a problem about user group - transaction code SQ03. After the release upgrade from 4.6C to ECC6 the user group, that I created in the old system, are not present in quality and production environment. In the development environment t

  • Need to Disable field in Table maintenance generator

    Hi Frds, I have created a custom table .But i stuck at one point. In the TMG one field is User ID and next field is filled with Full name of this User ID(made it noneditable). To get user name i implement '01' event in TMG. and its working fine. But

  • Rule below overprints descender

    We've been using the rule-below in some paragraph styles that use green type. The rule is tight to the baseline, so the descenders extend past it. On our old template, the green covers the black rule. But we've recently made a copy of that template a

  • Mail rules cannot save

    After upgraading to Mavericks (Mail 7.2) I am unable to save new rules, delete or modify current rules.  It looks like all is working well until I exit and restart Mail.  Changes are not saved.

  • What is the best program to run on my MacBook Pro to clean it up?

    can anyone tell me what the best program to run on a MacBook Pro to clean it up, make it run faster?