How is tag interface functionality implemented in Java ?

L

Lew

softwarepearls_com said:
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
 
L

Lew

Lew said:
ankur said:
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
 
L

Lew

ankur said:
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".
 
A

ankur

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 ?
 
S

softwarepearls_com

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.
 
L

Lew

Lasse said:
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.
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
 
L

Lew

Lasse said:
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.
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
 
L

Lasse Reichstein Nielsen

ankur said:
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
 
E

EJP

Lasse said:
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.
 
P

Patricia Shanahan

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
 
P

Patricia Shanahan

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
 
L

Lasse Reichstein Nielsen

EJP said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top