public class Teste {
private int value;
public int getValue() {
return value;
}
public Teste setValue(int value) {
this.value = value;
return this;
}
public static void main(String[] args) {
List<Teste> ls = new ArrayList<Teste>();
ls.add(new Teste().setValue(10));
List<Teste> un = Collections.unmodifiableList(ls);
un.get(0).setValue(5);
if(un.get(0).getValue() == ls.get(0).getValue()){
System.out.println("Iguais");
}else{
System.out.println("Diferentes");
}
}
}
This code proves that Collections.unmodifiableList does not ensures encapsulation
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.