+ 2

How to get object by name?

How to get object by object name?

6th Oct 2017, 10:49 PM
Tigran Sargsyan
Tigran Sargsyan - avatar
2 Answers
+ 4
you create a instance/object of your class/blueprint with the "new" keyword and then call it. hope this helps
6th Oct 2017, 10:52 PM
D_Stark
D_Stark - avatar
+ 2
It depends on what do you mean by "getting the object". Here's how i understand Java objects : When you declare an object ( like Object x;), you don't actually create an object, but just a reference to it. References are stored on stack ( part of memory) and objects live on the garbage collectible heap. When you create an OBJECT by calling its constructor ( e.g. new Object() ), it is created on the heap and it returns the REFERENCE - something like a remote control with which you can control your object - call mehods, set instance variables etc. ! -> The object is alive only when at least one reference to it is alive. When the object has no reference assigned to it, it is eligible for garbage collection - it dies. You can't get to it back. Object o = new Object(); new Object() - creates new object Object o; - o is now a reference to that object n Reference is kinda like an unique adress of where the object is stored on heap and Java uses these adresses to manipulate objects. So back to your question, the object is tied to the reference you have. You don't directly just get the object, you just have the reference. The name of reference like o in "Object o;" doesnt exist when the program runs, it has its own id like some hash value. Getting to that can be pain. At least in java. p.s. first answer, oh no what did i write ! :D, pls correct me if im wrong
6th Oct 2017, 11:44 PM
Plasmoxy
Plasmoxy - avatar