How to Increment a class Integer references value in java from another method

后端 未结 10 640
攒了一身酷
攒了一身酷 2020-12-09 02:29
package myintergertest;

/**
 *
 * @author Engineering
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void          


        
10条回答
  •  不知归路
    2020-12-09 03:19

    You can't. Java is strictly pass-by-value.

    See http://javadude.com/articles/passbyvalue.htm

    Your choices are to wrap the integer in an object (or array), pass that in and update, return a value, or make the integer a class/instance variable.

    Which is better depends on the situation.

提交回复
热议问题