Java 结果集-它是什么类型的对象?
我正在迭代ResultSet并将其保存到ArrayListJava 结果集-它是什么类型的对象?,java,jdbc,arraylist,resultset,memory-address,Java,Jdbc,Arraylist,Resultset,Memory Address,我正在迭代ResultSet并将其保存到ArrayList weatherData = Arrays.asList ( new WeatherInfo(rs.getDate(1), rs.getInt(2)... 当我做一个System.out.println(天气数据)时;我在Eclipse控制台中看到: [com.example.project.view.ChartsData]$WeatherInfo@66ee6cea,com.example.pro
weatherData = Arrays.asList (
new WeatherInfo(rs.getDate(1), rs.getInt(2)...
当我做一个System.out.println(天气数据)时;我在Eclipse控制台中看到:
[com.example.project.view.ChartsData]$WeatherInfo@66ee6cea,com.example.project.view.ChartsData$WeatherInfo@757d0531.....
这是什么意思?这是不是一个我可以用Java处理的值?
这是我可以在Java中使用的实际日期和int吗
谢谢您需要重写WeatherInfo类中的
toString()
方法。您看到的是它的默认实现,它显示了它的内存位置。您需要重写toString()WeatherInfo类中的
方法。您看到的是它的默认实现,它显示了它的内存位置。这是Java中一个典型的模型对象,带有toString()
方法。我使用了Intellij Idea(推荐!),它能够自动生成toString()
和其他方法,如equals()
和hashCode()
。我们发现在所有模型对象上使用这些方法对于调试和测试非常有用
运行main()
将输出:weatherInfo=weatherInfo{country='CA',probablyofprecipation=20}
public class WeatherInfo {
public static void main(String [] args) {
WeatherInfo weatherInfo = new WeatherInfo();
weatherInfo.setCountry("CA");
weatherInfo.setProbablyOfPrecipitation(20);
System.out.println("weatherInfo = " + weatherInfo);
}
String country;
int probablyOfPrecipitation;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getProbablyOfPrecipitation() {
return probablyOfPrecipitation;
}
public void setProbablyOfPrecipitation(int probablyOfPrecipitation) {
this.probablyOfPrecipitation = probablyOfPrecipitation;
}
@Override
public String toString() {
return "WeatherInfo{" +
"country='" + country + '\'' +
", probablyOfPrecipitation=" + probablyOfPrecipitation +
'}';
}
}
顶端提示!
我们使用一个名为
EqualsVerifier
的库来保证所有equals()
和hashCode()
实现都是正确的。这是Java中一个典型的模型对象,具有toString()
方法。我使用了Intellij Idea(推荐!),它能够自动生成toString()
和其他方法,如equals()
和hashCode()
。我们发现在所有模型对象上使用这些方法对于调试和测试非常有用
运行main()
将输出:weatherInfo=weatherInfo{country='CA',probablyofprecipation=20}
public class WeatherInfo {
public static void main(String [] args) {
WeatherInfo weatherInfo = new WeatherInfo();
weatherInfo.setCountry("CA");
weatherInfo.setProbablyOfPrecipitation(20);
System.out.println("weatherInfo = " + weatherInfo);
}
String country;
int probablyOfPrecipitation;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getProbablyOfPrecipitation() {
return probablyOfPrecipitation;
}
public void setProbablyOfPrecipitation(int probablyOfPrecipitation) {
this.probablyOfPrecipitation = probablyOfPrecipitation;
}
@Override
public String toString() {
return "WeatherInfo{" +
"country='" + country + '\'' +
", probablyOfPrecipitation=" + probablyOfPrecipitation +
'}';
}
}
顶端提示!
我们使用一个名为
EqualsVerifier
的库来保证所有equals()
和hashCode()
实现都是正确的。也谢谢你,@Matt Friedman。我在Eclipse中使用了“Generate-toString()”方法(Source-tab->Generate-toString()。这对我很有效。谢谢你,@Matt Friedman。我使用了Eclipse中的“generateTostring()”方法(Source选项卡->generateTostring()。这对我很有用。