【发布时间】:2014-03-19 15:42:28
【问题描述】:
我的程序从文本文件加载信息并创建一个对象数组,其中包含整数或字符串的信息。
然后我希望对象返回字符串或整数,具体取决于对象是保存整数值还是字符串值。
编辑... 所以这是我的类型类,如果文本文件中的字段是数字,则保存一个 int;如果字段是单词,则保存一个字符串,并且保存在 Type 数组中。
public class Type {
private String name;
private int value;
public Type(String name) {
this.name = name;
}
public Type(int value) {
this.value = value;
}
public String getName() {
return this.name;
}
public int getValue() {
return this.value;
}
public boolean isInt() {
boolean isInt = false;
if (this.value != 0) {
isInt = true;
return isInt;
}
return isInt;
}
}
所以在我的数组中可以是 Int 或 String,我想在我的主类中返回没有任何长语句的数据类型。
【问题讨论】:
-
到目前为止你尝试了什么?
-
我们想为您提供帮助,但如果没有具体问题,我们将无能为力。请发布您的代码(工作与否),并指定确切的问题。
标签: java string object int return