用LinkedList 后怎么调用这个元素里的个别方法?
一个类为:
public class client{
public String pseudo;
private int port;
private InetAddress adr;
client(String s ,int p, InetAddress adr){
pseudo = s;
port = p;
this.adr=adr;
}
client(int p , InetAddress adr){
pseudo = "anoyme ";
port = p;
this.adr = adr;
}
public String getPseudo(){
return pseudo;
}
public int getport(){
return this.port;
}
public InetAddress getadr(){
return this.adr;
}
public void setPseudo(String s){
pseudo = s;
}
public void setport(int p){
this.port = p;
}
public void setadr(InetAddress adr){
this.adr=adr;
}
}
在别的类中我用了 LinkedList 将上面的类 用作一个list :
public class server extends ServerSocket{
static LinkedList list_clients; //list of client
public server(int port) throws
IOException{
try{
ServerSocket serversocket = new ServerSocket(port);
while (true) {
Socket socket = serversocket.accept();
CreerConnexionThread(this,socket);
}
}
catch(IOException e){
System.out.println( "echouer d 'ecouter le port "+e);
}
finally{
close();
}
}
但是由于是 object 我怎样才能实现调用 list里的元素?
比如: 比如列出所有用户名:
for(int=0;i <list_clients.size();i++){
System.out.println(list_clients.get(i).peuso);
}
上面这个方法是错的,因为get()返回的是一个类为object的对象,请问各位大侠怎么能够实现呢?或者那个list 可以用别的 类 实现较为容易?
------解决方案--------------------for(int=0;i <list_clients.size();i++){
System.out.println(((client)list_clients.get(i)).peuso);
}