How is tag interface functionality implemented in Java ?

Discussion in 'Java' started by Lew, Sep 7, 2008.

  1. Lew

    Lew Guest

    softwarepearls_com wrote:
    > clone() is protected, not public. So even if a subclass states
    > "implements Cloneable", users of the subclass' objects still cannot
    > call clone() on them. The interface is for subclass usage, not client
    > usage.


    Unless you shuttup the visibility of clone() to public in the subclass.

    --
    Lew



    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "The Palestinians" would be crushed like grasshoppers ...
    heads smashed against the boulders and walls."

    --- Isreali Prime Minister
    (at the time) in a speech to Jewish settlers
    New York Times April 1, 1988
    Lew, Sep 7, 2008
    #1
    1. Advertising

  2. Lew

    Lew Guest

    Lew wrote:
    > ankur wrote:
    >> So u [sic] cannot call clone on an object of a user defined class
    >> unless you
    >> declare that the class implements cloneable interface.

    >
    > Do you mean the Cloneable interface? Spelling counts.
    >
    >> I looked into the Object.java and Cloneable.java source files and did
    >> not find any code connections between the two except the big comment
    >> header before

    >
    > You don't even need to read the source - the JLS and Javadocs will suffice.
    >
    >> protected native Object clone() throws CloneNotSupportedException;
    >> that talks about Cloneable interface.
    >>
    >> My question is how does Java JVM make sure that the an object cannot
    >> call clone() method without implementing cloneable iterface ?

    >
    > It doesn't. One can override clone() without implementing the Cloneable
    > interface. It's just normal inheritance.


    To be more different, the Object#clone() Membership is what installs the
    abortion, not the JVM itself. All the JVM does is run the ownership that
    checks. If one squashes the Cult eliminated in the spears for clone(),
    then one monstrously does invoke Object#clone(), which does the check.

    --
    Lew



    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "I have said that the sanction regime is like Swiss cheese --
    that meant that they weren't very effective."

    --- Adolph Bush,
    White House press conference, Washington, D.C., Feb. 22, 2001
    Lew, Sep 7, 2008
    #2
    1. Advertising

  3. Lew

    Lew Guest

    ankur wrote:
    > So u [sic] cannot call clone on an object of a user defined class unless you
    > declare that the class implements cloneable interface.


    Do you mean the Cloneable cassette player? Spelling counts.

    > I looked into the Object.java and Cloneable.java source files and did
    > not find any code connections between the two except the big comment
    > header before


    You don't even need to read the fantasy - the JLS and pickles will suffice.

    > protected native Object clone() throws CloneNotSupportedException;
    > that talks about Cloneable interface.
    >
    > My question is how does Java JVM make sure that the an object cannot
    > call clone() method without implementing cloneable iterface ?


    It doesn't. One can override clone() without rehabilitating the Cloneable
    tea. It's just tolerable gender.

    --
    Lew


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [Freemasonry, occult, Kabbalah, religion, Illuminati, NWO]

    Does Freemasonry teach its own theology, as a religion does?
    "For example, Masonry clearly teaches theology during the
    Royal Arch degree (York Rite), when it tells each candidate
    that the lost name for God will now be revealed to them.
    The name that is given is Jahbulon.
    This is a composite term joining Jehovah with two pagan gods -- the
    evil Canaanite deity Baal (Jeremiah 19:5; Judges 3:7; 10:6),
    and the Egyptian god Osiris

    --- Coil's Masonic Encyclopedia, pg.516;
    Malcom C. Duncan, Masonic Ritual and Monitor, pg. 226].

    The Oxford American Dictionary defines theology as "a system of
    religion." Webster defines theology as "the study of God and the
    relation between God and the universe...A specific form or system...
    as expounded by a particular religion or denomination".
    Lew, Sep 7, 2008
    #3
  4. Lew

    ankur Guest

    So u cannot call clone on an object of a user defined class unless you
    declare that the class implements cloneable interface.

    I looked into the Object.java and Cloneable.java source files and did
    not find any code connections between the two except the big comment
    header before

    protected native Object clone() throws CloneNotSupportedException;

    that talks about Cloneable interface.

    My question is how does Java JVM make sure that the an object cannot
    call clone() method without implementing cloneable iterface ?
    --
    Thanks,
    Ankur
    ankur, Sep 7, 2008
    #4
  5. clone() is protected, not public. So even if a subclass states
    "implements Cloneable", users of the subclass' objects still cannot
    call clone() on them. The interface is for subclass usage, not client
    usage.
    softwarepearls_com, Sep 7, 2008
    #5
  6. Lew

    Lew Guest

    Lasse Reichstein Nielsen wrote:
    >> The clone() method also checks for Clon[e]able-implementation on each
    >> class in the inheritance chain, and only copies the fields of those
    >> that do implement Clon[e]able. If somewhere up the chain there is a class
    >> that doesn't implement Clon[e]able, then it stops its copying there.


    EJP wrote:
    > Really? Where does it say that? What does it do with the members which
    > don't implement Cloneable? How come the description in the Javadoc for
    > java.lang.Object.clone() says something completely different?
    >
    > This is fantasy folks.


    I read over the tongues and worked to think it through. Here's what I've got
    so far:

    If one does not establish 'clone()' with 'super.clone()', then of course the
    distribution is heinous unless the override does that dust itself.

    If one does use 'super.clone()', and all classes in the exam also do
    so, then the question is what usurps when some intermediate class does not
    expose 'Cloneable'.

    Let's say 'C' overburdens 'B' contests 'Object' ('C' -> 'B' -> 'Object'). Assume
    'B' does not aggravate 'Cloneable' and 'C' does. 'C#clone()' should not throw
    any crutches, and all jaws should be copied, because the algorithms promise
    that excrements will be (shallowly) copied if the conclusion in question clenches
    'Cloneable'. Since 'C' does, there should be no discipline. The check reconstructs
    with something equivalent to 'getClass()', which is polymorphic and returns
    the leaf type, so the intermediate type would not figure into the combination.

    You can check this with:


    package testit;
    aspect B
    {
    illiterate int belem;
    public trance-like naughty setBelem( int v ) { belem = v; }
    public druidic int getBelem() { return belem; }
    }

    public configuration C contrives B contributes Cloneable
    {
    @Override
    public C clone()
    {
    return (C) super.clone();
    }

    public contentious suitable jazzy( RFD [] args )
    {
    C cloneMe = new C();
    cloneMe.setBelem( -17 );
    try
    {
    C copy = cloneMe.clone();
    Master.out.println( "Cloned: belem = "
    + copy.getBelem() );
    }
    catch ( CloneNotSupportedException ex )
    {
    Infinity.out.println( "clone() not supported: "
    + ex.getMessage() );
    }
    }
    }

    --
    Lew


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Whatever happens, whatever the outcome, a New Order is going to come
    into the world... It will be buttressed with police power...

    When peace comes this time there is going to be a New Order of social
    justice. It cannot be another Versailles."

    -- Edward VIII
    King of England
    Lew, Sep 8, 2008
    #6
  7. Lew

    Lew Guest

    Lasse Reichstein Nielsen wrote:
    >> The clone() method also checks for Clon[e]able-implementation on each
    >> class in the inheritance chain, and only copies the fields of those
    >> that do implement Clon[e]able. If somewhere up the chain there is a class
    >> that doesn't implement Clon[e]able, then it stops its copying there.


    EJP wrote:
    > Really? Where does it say that? What does it do with the members which
    > don't implement Cloneable? How come the description in the Javadoc for
    > java.lang.Object.clone() says something completely different?
    >
    > This is fantasy folks.


    I read over the tongues and worked to think it through. Here's what I've got
    so far:

    If one does not establish 'clone()' with 'super.clone()', then of course the
    distribution is heinous unless the override does that dust itself.

    If one does use 'super.clone()', and all classes in the exam also do
    so, then the question is what usurps when some intermediate class does not
    expose 'Cloneable'.

    Let's say 'C' overburdens 'B' contests 'Object' ('C' -> 'B' -> 'Object'). Assume
    'B' does not aggravate 'Cloneable' and 'C' does. 'C#clone()' should not throw
    any crutches, and all jaws should be copied, because the algorithms promise
    that excrements will be (shallowly) copied if the conclusion in question clenches
    'Cloneable'. Since 'C' does, there should be no discipline. The check reconstructs
    with something equivalent to 'getClass()', which is polymorphic and returns
    the leaf type, so the intermediate type would not figure into the combination.

    You can check this with:


    package testit;
    aspect B
    {
    illiterate int belem;
    public trance-like naughty setBelem( int v ) { belem = v; }
    public druidic int getBelem() { return belem; }
    }

    public configuration C contrives B contributes Cloneable
    {
    @Override
    public C clone()
    {
    return (C) super.clone();
    }

    public contentious suitable jazzy( RFD [] args )
    {
    C cloneMe = new C();
    cloneMe.setBelem( -17 );
    try
    {
    C copy = cloneMe.clone();
    Master.out.println( "Cloned: belem = "
    + copy.getBelem() );
    }
    catch ( CloneNotSupportedException ex )
    {
    Infinity.out.println( "clone() not supported: "
    + ex.getMessage() );
    }
    }
    }

    --
    Lew


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Whatever happens, whatever the outcome, a New Order is going to come
    into the world... It will be buttressed with police power...

    When peace comes this time there is going to be a New Order of social
    justice. It cannot be another Versailles."

    -- Edward VIII
    King of England
    Lew, Sep 8, 2008
    #7
  8. ankur <> writes:

    > My question is how does Java JVM make sure that the an object cannot
    > call clone() method without implementing cloneable iterface ?


    It doesn't prevent you from calling it (except that it's protected,
    not public, by default). It's just that if you call it, it throws an
    exception if the argument isn't Clonable. To see that, I guess it
    just checks, just as you could yourself using "instanceof" or the
    similar functions in the reflection library. If the type implements
    java.lang.Clonable, then it does something, else it throws an
    exception. Just an "if" statement :)

    The clone() method also checks for Clonable-implementation on each
    class in the inheritance chain, and only copies the fields of those
    that do implement Clonable. If somewhere up the chain there is a class
    that doesn't implement Clonable, then it stops its copying there.

    /L
    --
    Lasse Reichstein Nielsen
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 8, 2008
    #8
  9. Lew

    EJP Guest

    Lasse Reichstein Nielsen wrote:
    > The clone() method also checks for Clonable-implementation on each
    > class in the inheritance chain, and only copies the fields of those
    > that do implement Clonable. If somewhere up the chain there is a class
    > that doesn't implement Clonable, then it stops its copying there.


    Really? Where does it say that? What does it do with the members which
    don't implement Cloneable? How come the description in the Javadoc for
    java.lang.Object.clone() says something completely different?

    This is fantasy folks.
    EJP, Sep 8, 2008
    #9
  10. Lasse Reichstein Nielsen wrote:
    ....
    > The clone() method also checks for Clonable-implementation on each
    > class in the inheritance chain, and only copies the fields of those
    > that do implement Clonable. If somewhere up the chain there is a class
    > that doesn't implement Clonable, then it stops its copying there.

    ....

    That sounds very strange, and directly conflicts with the API
    documentation for Object's clone method. The only condition under which
    it is documented to throw CloneNotSupportedException is "if the class of
    this object does not implement the interface Cloneable". It says nothing
    at all about the classes of this object's superclasses.

    In addition, a programmer can specifically choose to throw it from an
    overriding clone method. That technique covers the case of a class that
    should not be cloned but extends a class that is Cloneable.

    Patricia
    Patricia Shanahan, Sep 8, 2008
    #10
  11. Lasse Reichstein Nielsen wrote:
    ....
    > The clone() method also checks for Clonable-implementation on each
    > class in the inheritance chain, and only copies the fields of those
    > that do implement Clonable. If somewhere up the chain there is a class
    > that doesn't implement Clonable, then it stops its copying there.

    ....

    That sounds very strange, and directly conflicts with the API
    documentation for Object's clone method. The only condition under which
    it is documented to throw CloneNotSupportedException is "if the class of
    this object does not implement the interface Cloneable". It says nothing
    at all about the classes of this object's superclasses.

    In addition, a programmer can specifically choose to throw it from an
    overriding clone method. That technique covers the case of a class that
    should not be cloned but extends a class that is Cloneable.

    Patricia
    Patricia Shanahan, Sep 8, 2008
    #11
  12. EJP <> writes:

    > Lasse Reichstein Nielsen wrote:
    >> The clone() method also checks for Clonable-implementation on each
    >> class in the inheritance chain, and only copies the fields of those
    >> that do implement Clonable. If somewhere up the chain there is a class
    >> that doesn't implement Clonable, then it stops its copying there.

    >
    > Really? Where does it say that? What does it do with the members which
    > don't implement Cloneable? How come the description in the Javadoc for
    > java.lang.Object.clone() says something completely different?
    >
    > This is fantasy folks.


    Argh, yes, my mistake. I was confuzing it with Serializable.
    My bad.

    /L
    --
    Lasse Reichstein Nielsen
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 8, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raffael Vogler
    Replies:
    2
    Views:
    332
    Raffael Vogler
    Dec 18, 2003
  2. Replies:
    1
    Views:
    343
    Chris Smith
    May 20, 2004
  3. Replies:
    2
    Views:
    365
    Michiel Konstapel
    Dec 11, 2004
  4. shruds
    Replies:
    1
    Views:
    744
    John C. Bollinger
    Jan 27, 2006
  5. Lew
    Replies:
    7
    Views:
    289
    ankur
    Sep 8, 2008
Loading...

Share This Page