how to get the command line arguments from another class with java

后端 未结 5 788
栀梦
栀梦 2020-12-18 22:18

so suppose I have a java package....

it\'s got the main class with the main method

and then it\'s got a whole bunch of other classes.....

my question

5条回答
  •  遥遥无期
    2020-12-18 23:07

    I'm kind of a newb at this, but you should be able to store the string[] args to a private instance variable, then make an accessor method for it. E.g.,

    public class test {
    private String[] myArgs = new String[10];
    public static void main(String[] args) {
    myArgs = args;
    }
    public String[] getArgs() {
    return myArgs;
    }
    }
    

    Not sure if it will work, but that's the idea.

提交回复
热议问题