Programmatically get name of object?

Is it possible to call a method on a object to get the name of that object---the variable name, not the name of its class?
Example:
Person fred = new Person();
Person barney = new Person();
List names = new ArrayList();
names.add(fred);
names.add(barney);
for (Object o : names) {
     System.out.println(o.methodThatGivesObjectName()); // should print "fred" and "barney"
     //...print out other info about the object...
}It seems like this should be possible, but maybe it's not. BTW, I know I could add a "name" field in this example, but I actually want to do this with other objects, like arrays.
Thanks,
Gregory

GregoryGarretson wrote:
Is it possible to call a method on a object to get the name of that object---the variable name, not the name of its class?
Example:
Person fred = new Person();
Person barney = new Person();
List names = new ArrayList();
names.add(fred);
names.add(barney);
for (Object o : names) {
     System.out.println(o.methodThatGivesObjectName()); // should print "fred" and "barney"
     //...print out other info about the object...
What if you add the following code before putting the objects in the list?
Person wilma = fred;
Person betty = barney;You've now got two variables pointing to each object. Which one is the object's "name" and why?
And if you add this code after adding to the list but before printing
Person tmp = fred;
fred = barney;
barney = tmp;Now fred and barney have swapped which object each points to. What are the "names" of the objects now, and why?

Similar Messages

  • Programmatically get names of all cases in a case structure

    Hi All,
              I have a subVI that is a state diagram (controlling some test equipment), with many states (i.e. each "state" is a case of a case structure), a text string chooses the case. All cases are named.
             Within this subVI is it possible for me to programmatically retrieve the text name for each case of this case structure? I wish to be able to retrieve these strings so that the main VI will only be able to call valid states.
            I have error handling to ensure that if an invalid state is called (by using the default case) that an error will be returned to my main vi, yet I would prefer to be able to retrieve the string to prevent any typo's etc.
          Not sure if I've explained this well.
         Thanks,
        ds1
    Solved!
    Go to Solution.

    You can do it with LabVIEW scripting, however, I wouldn't leave scripting in a final application. Use a typedef enum if you don't want to worry about this. If you want to keep it as a string (remember, this is a heavily debated subject) just make sure you test all cases before making it an executable and that should suffice. If you want to check to make sure it's a valid string, this seems like a bit overkill on the error checking! Just work it out when testing, or again as was said above, use a typedef enum.
    CLA, LabVIEW Versions 2010-2013

  • Getting name of object in action listener

    Ok, so, I have an array of 5 buttons named buttons[5]
    all of them have the text 'remove' on them. Is there a way to tell them apart in the action listener?

    event.getSource() will return the specific button instance.
    button.setActionCommand() and event.getActionCommand()
    can be used to differentiate between the buttons.
    Five buttons with the same label seems like sketchy design to me.
    How can the user tell what they're doing?

  • What is the Table/View name for getting the Database Object Dependencies

    I am running the Database Object Dependencies report to get the reference of Database Object and their respective Application Component.
    Applications xxxx -> Application Reports -> Shared Components -> Database Object Dependencies -> Compute Dependencies
    I want to develop a report for the same purpose, Just want to know what is the APEX Tables / Views they are using to run this report, so that I can use the same Tables to create my own report.
    Thanks,
    Deepak

    Hi Andy,
    when I am using the following query...I am not getting any result...
    select name, type, owner
    from all_dependencies
    where referenced_owner = 'APEX_030200'
    and referenced_name = 'WWV_FLOW_PATCHES'
    AND OWNER= 'XXXXXXX' --- (addeed this to the where clause)
    I modified the query.....I am getting the result.....
    select name, type, owner
    from all_dependencies
    AND OWNER= 'XXXXXXX'
    - But I am not getting which database object(table/view) is using which Application Page/Component like we have in Database Object Dependencies.
    - Also what is this REFERENCE OWNER & REFERENCE_NAME ----
    referenced_owner = 'APEX_030200'
    and referenced_name = 'WWV_FLOW_PATCHES'
    I am little bit confused, Can you pl expalin me in details......
    Thanks,
    Deepak

  • How to get text name text object and text id for long text

    Hi,
    I am trying to fetch Long text for a given order number from transaction CO04 in SAPScript. I know that I have to use Include X (OBJECT) XX ID XXX.
    How do I get the text name, text object and text id for the order header long text from Transaction CO04.
    Points will be awarded..
    Tushar

    Tushar,
    When you are in CO02, and are at the Long Text Tab,click on the Icon that is next to the Order Number at the top of the screen (this icon looks like a Pencil and a Pad of Paper and is called "Change Long Text"). When you click on this it will take you to the SAPscript Editor. Now hit Goto->Header and you will get the data you require.
    Hope this helps.
    Cheers,
    Pat.
    PS. Kindly award Reward Points as appropriate.

  • How to get an initialised Object according to it's name?

    How to get an initialised Object according to it's name?
    For example I have 5 HashSets (initialised, with data) hs1 hs2 hs3 hs4 and hs5
    Sometimes I want to get one of them according to it's number : "hs"+number
    How this can be done (method class.forName is dedicated to antoher thing).
    Thanks

    I forgot to write that I do not want to use a Map :)
    (sure, it' possible via Map, no question).
    But in Perl, for example, I could simply write
    $ab="col" + "or";
    $color="Beidge";
    and than I can use address to a variable $color in
    such a way : $$ab
    ... So if a Map is an only way... than it will be a
    Map... pity..I do not really know Perl so I can not comment on it; but, are there any compiled languages (at least compiled to the degree of Java) that support this construct? All of the programming languages that I can think of that have this construct are more along the lines of scripting languages.
    Just curious.

  • Is it possible to programmatically get the label name(s) of a VI's connector pane IPs and OPs?

    I can get the number of IPs & OPs using the metrics VI but not the variable names, any help much appreciated.
    Certified LabVIEW Architect

    You can get names of all controls and of all indicators. Use Get All Controls method of VI server.
    This is not exactly that you want but may be will help you.

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • How do I get an activeX object reference from a LabVIEW ActiveXContainer ref?

    How do I get an activeX object reference from a LabVIEW ActiveXContainer ref?
    I'm trying to control an ActiveX object (a Web Browser) from another VI and need to get the object reference programmatically. I can get the LabVIEW ActiveXContainer reference, but am lost on how to get the reference for the object _inside_ the container.

    Hi Lee,
    The reference to the container is actually also accessing the object inside the container. Use the Property Node and Invoke Node to access properties and launch methods for the object. I've attached a small example that passes the reference to a SubVI and invokes a method inside the SubVI.
    - Philip Courtois, Thinkbot Solutions
    Attachments:
    WebContainer.zip ‏21 KB

  • Why do I get "Error 1 occured at Config Data Registry.vi(get data) invalid object 0" while starting my application?

    Why do I get "Error 1 occured at Config Data Registry.vi(get data) invalid object 0" when starting my application created in LabVIEW 7.1?  I am starting the application in a PXI rack running Windows XP.  I have an executable written in LabVIEW 7.0 that runs without this error.  After clicking the Continue button in the error, the application seems to continue happily.
    Is there something I need to include when I make the executable?
    I would like to understand and eliminate this start up error.
    Thanks in advance.
    BobNorth

    Hi Bob,
    I looked through the program and I figured out where the error is coming from, and potentially what is causing it. In a lot of the cases of the program you are searching a 1-D array for the name of the case, and if you don't find it then it skips the function and gives "Error 1 occurred at Config Data Registry.vi(CASENAME) invalid object 0". I attached a screenshot that shows what I mean. The Search 1-D Array.vi is returning a -1 which means it didn't find the case. The reason I believe this is happening is because the shift register for that array is not initialized. While the other cases "reset" and "register" interact with the array shift registers and most likely create the array you need, if the program defaults to the "get data" case then it will try to run that before registering and won't have an array to search. This would also explain why it only has this problem at first and seems to run just fine after that. To fix this you should either make an initial array and wire it into the shift register or make the "reset" case the default as opposed to the "get data" case.
    Regards,
    Peter W.
    Attachments:
    Config Data Registry.png ‏55 KB

  • How to  get the profile object in simple java class  (Property accessor)

    Hi All,
    Please guide me how to get the profile object in simple java class (Property accessor) which is extending the RepositoryPropertyDescriptor.
    I have one requirement where i need the profile object i.e i have store id which is tied to profile .so i need the profile object in the property accessor of the SKU item descriptor property, which is extending RepositoryPropertyDescriptor.
    a.I dont have request object also to do request.resolvename.
    b.It is not a component to create setter and getter.It is simple java class which is extending the RepositoryPropertyDescriptor.
    Advance Thanks.

    Iam afraid you might run into synchronization issues with it. You are trying to get/set value of property of a sku repository item that is shared across various profiles.
    Say one profile A called setPropertyValue("propertyName", value).Now another profile B accesses
    getPropertyValue() {
    super.getPropertyValue() // Chance of getting value set by Profile A.
    // Perform logic
    There is a chance that profile B getting the value set by Profile A and hence inconsistency.
    How about doing this way??
    Create PropertyDescriptor in Profile (i.e user item descriptor), pass the attribute CustomCatalogTools in userProfile.xml to that property.
    <attribute name="catalogTools" value="atg.commerce.catalog.CustomCatalogTools"/>
    getPropertyValue()
    //You have Profile item descriptor and also storeId property value.
    // Use CustomCatalogTools.findSku();
    // Use storeId, profile repository item, sku repository item to perform the logic
    Here user itemdescriptor getPropertyValue/setPropertyValue is always called by same profile and there is consistency.
    -karthik

  • The technical name of object QVIW zabcd is not valid

    Hello Gurus
    I am facing a weird problem.
    I run a query it works fine but when I try to save the view by right click -- save view it ask me for the Description and Technical name after putting this information I press save. Istead of saving it it gives me error "The technical name of object QVIW zabcd is not valid"
    Please help me asap
    Our system is on SP18 both for abap and Java

    Hi Bala Duwuri,
    Thanks for the input...
    Can you please give me your valuable inputs on this ........
    I have a standalone custom web dynpro application which needs to be linked to standard team viewer application.
    What I want is I should be able to select the employee from the Team Viewer iView and supply the information to the Custom Application so that it gives me output based on that.
    Right now am following the below link But in that no where they were talking about the webdynpro eventing.
    then how come two views will get linked fucntionally so that team viewer will pass the information to my custom WD application??????????????????? Please help
    Please give me a clear view on how to integrate the team viewer application with custom development WD application.
    If code is required pls provide that also.............
    I would appreciate the useful inputs with higher points.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/how%2bto%2bread%2binformation%2bfrom%2bthe%2bteamviewer%2bin%2bweb%2bdynpro
    Thanks in Advance,
    Dharani

  • How Do I Convert a String that Names an Object to a Reference to the Object

    You get many program-specific object names in the XML that is returned by describeType.  Suppose I find an object that interests me.  What is the best way to convert the String that names the object (e.g. the id of the object) to a reference variable that points to the object? 

    Sure.  I am working on a complex application that involves several ViewStacks, several Accordions, some checkboxes, some radio buttons, some text boxes.  These components are scattered about, but all are children of a base class that is successfully enumerated by
    var classInfo:XML = describeType(vwstk);
    Suppose I write a loop as follows:
     for each (var a:XML in classInfo..accessor){
    Inside that loop I have a series of tests like
    if (a.@type == "mx.controls::CheckBox"{
    Then, I iterate thru all of the children of the base class as in:
    for  
    (var u:Object in vwstk)
    {        if  
    Inside the if I persist the checked/not checked status of the checkbox.
    The tricky part is going from the string a.@name to the Object reference u.  I doubt my proposed method will work.  Do you have a better idea?

  • Getting info on objects loaded via xml

    Hello:
    i am a beginner/intermediate as3 coder, and i am stuck on
    something related to objects loaded via XML.
    i am able to load JPEG images onto a simulated "shelf", but i
    am trying to arrange them on the shelf (like a store shelf) so that
    each new item is placed directly next to the previous item as they
    load. i can get it to work on a very basic level by specifying the
    spacing between items manually betwen the code, but to makre this
    reuseable and efficient, the ideal is to have the "next" object
    loaded be placed on the shelf based on the width of the previous
    object. but when i try to access the width of the object that is
    loaded via the imageLoader, i can;t find it. if i trace the image
    loader wifth, it is 0; i have tried several ways to name the object
    as it loads and then get/save its dimensions somehow, but i am not
    having any luck. i use all the Lynda titles and i also use some of
    the better books, but i just can;t seem to solve this.
    any hellp would be appreciated.
    thank you.

    Thak you for this -- it did help somewhat, but i am still
    stuck.
    When i use the contentLoaderInfo listener, you are right, i
    can discern the width of the loader. but when i do this it only
    works for the last item loaded. here is my problem -- i am trying
    to load graphics dynamically, and have each graphic go to it's
    proper "place" on a simulated shelf -- so the foirst object might
    go to (0,0), then next object should go directly to the right of
    the first object, etc, etc. and i am loading all this dynamically
    from an xml file. if i just specify a distance, then i can get
    everything to load at uniform distances from each other. problem is
    each of the graphics has a unique width, height, etc, so i need to
    be able to "catch and capture" this info as each one is loaded.
    when i wait until the entire loader has loaded, the only
    peopoerties left for me to capture and use are the propoerties of
    the last itm loaded.
    any ideas on how to do this -- anyone?
    thanks very much, i just can't seem to figure this out.

  • Record Management: get logical document object from physical doc. object

    Hello,
    I'd like to get logical document from physical document (sdok object - stricture containing class and objid).
    There is BAPI for "opposite direction": SDOK_LOIO_PHYSICAL_OBJECT_GET. By this FM I can get physical document's sdok object from logical document's sdok object.
    Can anybody tell me BAPI's name for it?
    I tried SDOK_PHIO_LOGICAL_OBJECT_GET, but this BAPI doesn't exist.
    Best regards,
    Josef Motl

    Josef,
    There are I don't believe there are any bapi's for this. You probably have to do this via ABAP OO. Create an object of the type CL_SRM_DOCUMENT. This is your logical (LOIO) object of your document. You have to enter the documentclass and the objectid of the document. This class has a method get_variant. This variant is your fysical (PHIO) object of the document. Use version and variant 0 so you will get the latest version object of your document.
    If this isn't the answer, can you please explain where do you get the fysical object from if you haven't got the logical first?
    Regards,
    Tjalling-Jan

Maybe you are looking for

  • DVD Player Hangs

    Since Leopard upgrade a DVD that plays fine on a regular player will not play on iMac. It plays for a while then hangs while a message says "skipping over damaged area". Had to power off to get out of DVD Player. Coould not get to force quit.

  • Grouping multiple subscriptions for streaming notifications

    Hello, I want to subscribe to Exchange (ver. 2010) streaming notifications in order to receive events for multiple mailboxes. I don't want to open a separate connection for each mailbox, although from what I've read so far I need a separate subscript

  • Display Icon in write report output

    Hi, How do I display/write an icon to the screen? Thanks, John

  • Checking one IMAP account from 2 different Macs using Mac Mail

    Greetings, New to the forums... Have recently switched from using POP 3 account methods to IMAP (our new host provider encourages IMAPs, due to e-mail dupes showing up + more stable). Both my biz partner and I check the same accounts form both of our

  • Foreign Keys on a Table

    Hello, On a MySQL Database this Table is given: CREATE TABLE Device ( DeviceID int(11) NOT NULL auto_increment, TypeID int(11) default NULL, Type ID is a foreign Key that references to another Table which maps the number to a VARCHAR fpr example 1 --