From: Robert Date: 2003-05-21T06:54:22+09:00 Subject: Re: Ruby reference recommendations "Marcin 'Qrczak' Kowalczyk" schrieb im Newsbeitrag news:200305202113.47799.qrczak@knm.org.pl... > Dnia wto 20. maja 2003 18:53, Robert Klemme napisa�: > > > Since there is no way in Java to define a class a having immutable > > instances > > There is: just don't provide any method which changes attributes. > A pity that an attribute can't be exposed read-only. Well, but this is no strict class level declaration (like "abstract" is) that could be used to automatically detect immutability of a class. In Java a compiler could evaluate all fields and if they are final assume immutability. But then there's still inheritance... In Ruby I guess it would be more complicated, because the code of a class can change all the time. > > IMHO the approach taken in Java (and in Ruby also) is the most > > reasonable one. > > The flaw in the Java approach is that there is no single operation which is > both definable for user classes (and defined for classes like string to > compare contents) and works for int (and other primitive types). Yepp! robert