class services
{
public int id;
public String name;
public String ip;
public String port;
}
在另一个类里,构造一个services类的vector
Vector service = new Vector();
while (restultSet.next()) {
services Service = new services();
Service.name=restultSet.getString(1);
Service.ip=restultSet.getString(2);
Service.port=restultSet.getString(3);
Service.id=restultSet.getInt(4);
service.add(Service);
}
如何取出每个类里的变量???
for(int i = 0;i < service.size();i++){
socket = new Socket(service.get(i).ip, Integer.parseInt(service.get(i).port));
报错说找不到变量ip
------解决方案--------------------
试下这样
Vector<services> service = new Vector();
PS:LZ的代码很不规范啊。。。。。
------解决方案--------------------
service.get(i)的结果是Object,当然找不到ip字段
要么用泛型,要么用强制转换
------解决方案--------------------
就我看来有一下几个问题:
1、ls的代码很不规范
2、实现了泛型就得为泛型指明类型。
3、
- Java code
Vector<services> service = new Vector();while (restultSet.next()) {services Service = new services();Service.name=restultSet.getString(1);Service.ip=restultSet.getString(2);Service.port=restultSet.getString(3);Service.id=restultSet.getInt(4);service.add(Service);}