Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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,我现在拥有的代码 public UUID uuid; public long login; public long logout; public static enum Key { UUID, LOGIN, LOGOUT; } public User(UUID u) { uuid = u; // only the uuid needs to be set here } public Object get(Key key) { // return th

我现在拥有的代码

public UUID uuid;
public long login;
public long logout;

public static enum Key {
    UUID,
    LOGIN,
    LOGOUT;
}

public User(UUID u) {
    uuid = u; // only the uuid needs to be set here
}

public Object get(Key key) {
    // return the object
}

如何通过将枚举小写来获取字段,然后在get方法中作为模糊对象返回,如上图所示?

其他注释有效,但如果需要使用枚举。。。 将字段定义为对象数组如何?
注意:您需要长对象而不是“长”类型。

为什么这样做?您有3个枚举和3个字段,使用if-else-if.@SotiriosDelimanolis我以前没听说过或见过,您能给我举个例子吗?为什么要这样做而不是使用标准的getter?会有很多字段。对每个字段使用1个getter和1个setter会导致类非常混乱。反射?它可能有用UUID呢?它也需要一些爱:Plong不能被铸造成物体,反之亦然?