Pourquoi pas une interface "Immutable" en Java ?
Bonjour,
Je viens d'envoyer un mail aux gens de chez Jakarta Commons Lang pour leur demander pourquoi ne pas intégrer une interface Immutable vide (sans méthode), servant à marquer avec certitude quelles sont les classes qui "déclarent respecter ce contrat" (impossible à déterminer par introspection) : en effet une RFE [Request For Enhancement] officielle existe depuis 2001 mais pour l'instant pas de conclusion chez Sun.
Bref voici le mail en question puis la réponse (désolé pour mon anglais)...
Citation:
Envoyé par moi
Hello,
I'm very surprised not to find any org.commons.immutable.Immutable empty
interface (as java.lang.Cloneable do) : neither into the actual version of
Commons Lang, nor into the TODO list. If there's any reason for that lack
?
I officially suggest you to add it... waiting for an official decision
about the Sun request
http://bugs.sun.com/bugdatabase/view...bug_id=4617197 !
NB_ I think it could be a good idea, into the class Javadoc of this new
no-method Immutable interface, to say that it is only a declarative
interface and to add any precision about what are the real requirements it
implies (final class, private attributes, no setters, getters returning
copies...)
Thancks to say if I'm totally wrong :-)
cordially
Citation:
Envoyé par eux
It's best to send such questions to
commons-dev@jakarta.apache.org
(usually after subscribing first
'commons-dev-subscribe@jakarta.apache.org'), or to add them to the
JIRA instance (
http://issues.apache.org/jira/browse/LANG).
There's not an Immutable interface because Lang aims not to force
religion (for use of a better word) on the developer. There are very,
very few interfaces in Lang and neither of them need to be implemented
by developers to get functionality.
There's also not a lot of concrete value in marker interfaces,
Cloneable is a bad example as along with Serializable it should have
had the methods declared in it instead of linking to JVM magic. So
that's another reason for no marker interfaces in Lang - we can't do
the JVM magic.
Bref est-ce vraiment une si mauvaise idée de faire confiance aux développeurs à propos d'une propriété de classe "quasiment indémontrable" autrement que de manière déclarative ?
J'en appelle à vos avis d'experts!
MERCI D'AVANCE
;)