Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33201

Re: Why it necessary to implement clonealbe interface?

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Why it necessary to implement clonealbe interface?
Date 2015-11-25 16:41 -0500
Organization Aioe.org NNTP Server
Message-ID <n359tj$rde$1@speranza.aioe.org> (permalink)
References <n31vi5$dkg$1@speranza.aioe.org> <n321jk$3uj$1@dont-email.me> <n330jp$5ba$1@speranza.aioe.org> <84654386-4302-4358-9143-5280e2a7111d@googlegroups.com>

Show all headers | View raw


On 11/25/2015 2:01 PM, Eric Douglas wrote:
> On Tuesday, November 24, 2015 at 7:50:28 PM UTC-5, Arne Vajhøj wrote:
>> To this excellent explanation I would just like to add that
>> today (today as in last decade) instead of a marker interfaces
>> one would usually use an annotation. But Cloneable goes back
>> to Java 1.0.
>
> So you think it does just look stupid because it was written into Java 1.0?

I think it looks the way it does because that was the only way in
Java 1.0-1.4 and that it would have been made differently in Java 1.5-.

Nothing stupid really.

> My only other thought for wanting an interface class was to say whether or not you want your cloneable object to return the condition
> if (myObject instanceof Cloneable) {

With annotation you would use:

if(myObject.getClass().getAnnotation(Cloneable.class) != null) {

That in itself does not look like an improvement.

But first it uses the mechanism intended for such thing:
- interfaces specify what methods implementing classes must have
- annotations provide meta-data about class (and other)

It is meta-data not required methods that we need here.

And secondly it provides additional capabilities.

One could define an mode attribute so you could use:

@Cloneable(mode=CloneMode.SHALLOW)

and:

@Cloneable(mode=CloneMode.DEEP)

and access it from the processing code.

Arne

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why it necessary to implement clonealbe interface? Xue Feng <xf.lotus@yahoo.com> - 2015-11-24 23:28 +0800
  Re: Why it necessary to implement clonealbe interface? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-24 11:03 -0500
    Re: Why it necessary to implement clonealbe interface? Arne Vajhøj <arne@vajhoej.dk> - 2015-11-24 19:49 -0500
      Re: Why it necessary to implement clonealbe interface? Eric Douglas <e.d.programmer@gmail.com> - 2015-11-25 11:01 -0800
        Re: Why it necessary to implement clonealbe interface? Arne Vajhøj <arne@vajhoej.dk> - 2015-11-25 16:41 -0500
  Re: Why it necessary to implement clonealbe interface? Lew <lewbloch@gmail.com> - 2015-11-29 23:00 -0800

csiph-web