Results 1 to 3 of 3
  1. #1
    cknew1 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Indirect object access in JAVA

    Indirect object access in JAVA

    I am trying to understand how to indirectly access objects.

    Using the following simple Customer Class. For example, here are two of 50 Customer objects. They are Bill and Bob.

    public class Customer {
    private int CustNum;
    private String name;
    private String homePhone;


    Customer Bill = new Customer(100, "Bill West","1234567890");
    Customer Bob = new Customer(101, "Bob East","1234567891");

    I then wish to perform tasks on a certain object.
    i.e. I want to work on object "Bob"

    String custObj= "Bob";

    int dummynum = &custObj.CustNum;

    I would like dummynum to contain the value 101.

    You could even extend this to

    String custObj= "Bob";
    String custField= "CustNum";

    int dummynum = &custObj.&custField;

    The thought is to create dynamic flexible methods.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Indirect object access in JAVA

    What does "indirectly access" mean? You need a reference to an object to be able to access it.

    If you want to get a reference to an object using a String, put the objects in a Map with the String as the key and the object as the value.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Indirect object access in JAVA

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Can't access Object of JavaScript
    By scsvel in forum New To Java
    Replies: 2
    Last Post: 06-28-2011, 08:11 AM
  2. Access object variables
    By AcousticBruce in forum New To Java
    Replies: 6
    Last Post: 01-10-2011, 10:41 AM
  3. Object access between classes
    By qazplm123890 in forum AWT / Swing
    Replies: 1
    Last Post: 03-05-2009, 06:00 AM
  4. how to access to an object from a thread
    By tamayo in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 05:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •