Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
枚举类型不能像java中的对象引用那样传递到函数中?_Java - Fatal编程技术网

枚举类型不能像java中的对象引用那样传递到函数中?

枚举类型不能像java中的对象引用那样传递到函数中?,java,Java,如果我在这个方法中更改a的值,那么在这个方法之外的a的值也应该更改。但是 object a = new object(); method(object a); 如果我改变这个方法中的b值,这个方法之外的b值,我发现它没有改变。我不知道为什么 枚举不是类型,枚举是声明性关键字。此外,参数类型不是在方法调用中声明的,而是在方法声明中声明的。这将更加正确: enum b = enum.something; method(enum b); 由于您正在传递对象引用,因此更改将反映在实际对象上 Ob

如果我在这个方法中更改a的值,那么在这个方法之外的a的值也应该更改。但是

object a = new object(); 
method(object a);
如果我改变这个方法中的b值,这个方法之外的b值,我发现它没有改变。我不知道为什么

枚举不是类型,枚举是声明性关键字。此外,参数类型不是在方法调用中声明的,而是在方法声明中声明的。这将更加正确:

enum b = enum.something; 
method(enum b);
由于您正在传递对象引用,因此更改将反映在实际对象上

Object a = new Object(); 
method(a);
public void method(Object a){
        // do operation on Object a 
}

枚举是用于保持其状态的常量。就像公共静态最终常数一样。

不确定你在做什么或问什么,但我知道的似乎与你的问题有关:

An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.

Because they are constants, the names of an enum type's fields are in uppercase letters.


这段代码有太多的错误,使得这个问题无法回答。是的,你有我的问题。我只是不知道为什么你给我的关于enum的第二个案例,这并没有改变bOutside@理查德·西泽西
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.

Because they are constants, the names of an enum type's fields are in uppercase letters.
MyObject aOutside = new MyObject(); // 
method(MyObject a) {
  a.setSomeValue("value"); // Change the object referenced by aOutside
  a = new MyObject(); // Does *NOT* change aOutside
}
enum MyEnum { AAA, BBB; }
MyEnum  bOutside = MyEnum.something; 
method(MyEnum b) {
  b = MyEnum.AAA; // Does *NOT* change bOutside
}