Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not quite. eg:

public final Date date;

date.setTime(1);

That's not immutable.



The bean convention doesn't help you with that one though; if you have private Date date; public Date getDate() {return date;} then people can still do getDate().setTime(1);


Yeah, but with a getter you can make getDate return a copy of the Date object to enforce immutability.


The fact that java.util.Date is terrible is so many ways should go without saying.


Yep, the thing is that Date is immutable. I think that this public final immutable rule is ok, but one has to ensure the fields themself are really not modifiable.


The Java Date class is not immutable.


So you can use a wrapper or Joda time library.


A class with mutable fields that a caller can mutate is not immutable.


Yeah, but getDate().setTime(1); works the same way.


Not if getDate() returns a copy of the underlying member.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: