Java : Best way to pass int by reference

后端 未结 7 2177
不知归路
不知归路 2020-11-28 05:36

I have a parsing function that parses an encoded length from a byte buffer, it returns the parsed length as an int, and takes an index into the buffer as an integer arg. I

相关标签:
7条回答
  • 2020-11-28 06:13

    You can design new class like this:

    public class Inte{
           public int x=0;
    }
    

    later you can create object of this class :

    Inte inte=new Inte();
    

    then you can pass inte as argument where you want to pass an integer variable:

    public void function(Inte inte) {
    some code
    }
    

    so for update the integer value:

    inte.x=value;
    

    for getting value:

    Variable=inte.x;
    
    0 讨论(0)
提交回复
热议问题