• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which are the problems? - About ArrayList  RSS feed

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List<Metodo1> lista = new ArrayList<Metodo1>();
lista.add(01);
lista.add(new Metodo1(01));


-----------------------------------------------------------------------

package metodos;

public class Metodo1 {

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
private long id;
private String nome;
}
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First of all, there's no constructor that takes one int parameter in class Metodo1.


Second:

With the following line you say that your List will hold Metodo1 objects



Then you change your mind an you write



The compiler won't be so happy about that.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you ought to know by now how much more difficult it is to read code without "code" tags.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!