I am really scratching my head about this, this should be easy, but I never saw any explanation how it should be done. AT the moment I do it by giving the class in question its own number. Now I have again the same problem and want to find a better solution.
Answers
At the moment I am trying things like;
int numof = this.tinyButton[] ;
which does not work, it gives "unexpected token ["
Objects aren't "aware" about which variable or structure happen to be referencing them!
new
instantiates a PVector object.Perhaps you should take a look at Processing's references about arrays too:
http://processing.org/reference/Array.html
http://processing.org/reference/arrayaccess.html
Crap!, so as I understand its mathematically impossible for an object to know where it came from 8-X So the only way for an object to get to know its own name/number is to spoon fed it, is that right?
Anyway, thx for the answer :) I guess I know know what to do ~O)
Objects got their own identity, which is their unique reference
this
.That is, every time a
new
object is instantiated, its ownthis
is instantiated too!Also, a hashCode() is generated:
Okay, I solved with this; tinyPush[i].update(i);
Where the second "i" is the array number of the class
very easy to do in retrospect.
Your third answer is intriguing, how do you use the hashCode number? Its use seems to be somewhat abstract this way. :-B
That i variable represents some index of an array object referenced by tinyPush variable.
Which in turn is completely independent of what value is stored in a particular index!
If a reference is stored in a structure, the object that reference points to isn't aware of that!
The index belongs to the structure alone. It's not a property of the stored reference! (~~)
There are some complex structures which care about that plus equals(), like the HashMap for example:
http://processing.org/reference/HashMap.html
http://docs.oracle.com/javase/8/docs/api/java/util/Map.html
Well, it works now, my problem is/was like a house, the house has a number, but is not capable knowing its own number, it only can if somebody tells it. So that is what I did.
But your explanation really gives me a bigger sense of the architecture of a language. :)>-
"its mathematically impossible for an object to know where it came from"
Yes. Even more as the same object can be referenced in several variables and arrays.