Java中类之间的信息交换

时间:2017-06-12 01:11:35

标签: java class variables object compiler-errors

我有两个问题:

首先:我得到"oauth_token": { "type": "string", "description": "OAuth 2.0 token for the current user.", "location": "query" }, ,我不知道如何解决它

第二:我在其他项目中使用了类似的语法,StackOverflowError没有问题。第二个问题是我的代码中的注释。我想在课程StackOverflowError中更改x的值,并在课程ChangeValueOfVariable中使用它。

DisplayValueOfVariable

我知道,我可以在class DisplayValueOfVariable{ ChangeValueOfVariable change = new ChangeValueOfVariable(); public int x = 0; public void showX(){ System.out.println("Value of x: "+x); //There is still x = 0 } public void changedX(){ change.changeValue(); System.out.println("Value of x: " +x); // Unfortunately there is still x = 0, but I want here to use changed value } } class ChangeValueOfVariable{ DisplayValueOfVariable disp = new DisplayValueOfVariable(); public void changeValue(){ disp.x++; System.out.println("Value of x: "+disp.x); // Now x = 1 } } class Start{ public static void main(String[] args) { DisplayValueOfVariable displayValueOfVariable = new DisplayValueOfVariable(); displayValueOfVariable.showX(); displayValueOfVariable.changedX(); } } 中更改x,但如果我有更多变量,则无法帮助我清理代码。

感谢您的帮助;)

我知道如果我会做这样的事情

public void changedX()

这将是我的预期结果,好的。

据我所知,如果我只使用一个类(我附加了),我的代码将编译时没有错误,代码会更简单。 不幸的是,我必须拆分我的代码并将其保存为更多的类。 我对已存在的变量的操作(在其他类中)有问题。

0 个答案:

没有答案