Re: Need help! cloning an object
Re: Need help! cloning an object
- Subject: Re: Need help! cloning an object
- From: LD <email@hidden>
- Date: Fri, 12 Aug 2005 13:25:54 +1000
Hi there,
On 11/08/2005, at 6:12 PM, Amedeo Mantica wrote:
Hi, this is my problem
I have this variable declarations
--------------------------------------------------------------------
public MyClass variable
/** @TypeInfo MyClass */
public NSMutableArray variableArray;
---------------------------------------------------------------------
and this code...
variable=variableArray.objectAtIndex(i);
---------------------------------------------------------------------
I got an "INCOMPATIBLE TYPES" ERROR
As you should. Java is a strongly typed language and as such
assigning objects of type Object to someVariable of
SomeTypeOtherThanObject (e.g., MyClass) will cause problems with the
compiler. You need a correct cast as Michael points out.
===
Before going any further with WO, I suggest you do your best to get a
better understanding of the Java language. Otherwise you'll find the
going very tough.
http://java.sun.com/docs/books/tutorial/
http://developer.apple.com/referencelibrary/GettingStarted/GS_Java/
index.html
There are at least two fundamental problems with your understanding
from the above code...
1) variable=variableArray.objectAtIndex(i); // IS NOT A CLONE OPERATION!
You need to understand the nature of working with objects. Objects
are not primitives. You don't get clones of objects via the
assignment operator ('=') but a reference to the object.
2) the "@TypeInfo MyClass" comment tells us that you need to cast all
objects that you either remove from, add to, or reference in the
array to the type MyClass (or any subtypes thereof). e.g.,
MyClass variable;
variable = ( MyClass )variableArray.objectAtIndex( i );
These are fundamental things about the Java language. Tip: look in
the API for the return type of a method. If the return type is not
the same type or a subtype of what you want to assign it to - then
you'll need to cast.
with regards,
--
LD
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden