0

I've pasted the classes relevant to my question below. vis2 is an instantiated version of the Connect2 class. When debugging, if I'm in the Connect class, and then jump into the vis2.setURL(String url) method, this is listed in the Variablesview. The value for this is listed as Connect2 (id=22).

Is it possible to have Eclipse show WHICH instance of Connect2 this is describing (in this case vis2)? Thanks in advance.

Main.java

public class Main {
  public static main(String[] args) {
    Connect connect = new Connect();
    connect.findLocid();  
  }
}

Connect.java

public class Connect {
  public void findLocid(){
    Connect2 vis2 = new Connect2();
     vis2.setURL("Https://www.someurl.com");
     vis2.execute();
  }
}

Connect2.java

public class Connect2 {
  private String url;
  public Connect3 me;

  public void execute() {
    me = new Connect3(this.url);
    me.connect();
  }

  public void setURL(String url) {
    this.url = url;
  }
}
6
  • Objects don't have names in Java... id=22 is Eclipse trying to show you which object it is. Commented Jan 5, 2015 at 4:27
  • A variable name is just a human-friendly identifier for object references, the names you see in a debugger are only there due to "debug information" being compiled into the class files. As far as I know, what you want is impossible. The names you see in a debugger are named references to objects on a given object (graph of names), when you step in that method, you're looking at the root of that graph as "this", the debugger doesn't know anything about who holds refs to "this". There could be 1,000 variables all holding a reference to "this" with different names, which one would it show? Commented Jan 5, 2015 at 4:28
  • You could add a name String to your object for debugging purposes Commented Jan 5, 2015 at 4:58
  • @Alex but aren't the actual containers for the variables identified by a Id? So wouldn't the "this" for one instance have a different Id than the "this" for another instance of the constructor? On that note, how come each time I debug my application, the variables are assigned completely different Id's? Does't the application more or less run in a logical cause and effect manner (excluding debugging challenges when running multiple threads at one time)? Commented Jan 8, 2015 at 7:28
  • @immibis thanks. How come the id for a variable changes each time I run or debug? I'd have assumed that being a cause/effect series of logical progressions, the ID's would be assigned the same each time provided nothing has changed. How does it choose an ID for a variable? Is it based on available resources? Commented Jan 10, 2015 at 16:21

1 Answer 1

1

One way you could fix this problem is to add a name variable to each of your classes. For example, Connect2 could be modified as such:

public class Connect2 {
    private String url;
    public String name;
    public Connect3 me;
    public Connect2(String name) {// and the rest of your arguments
        this.name = name;
    }
    public void execute() {
        me = new Connect3(this.url);
        me.connect();
    }
    public void setURL(String url) {
        this.url = url;
    }
}

Then you can simply use the name as follows.

Connect2 <variable name> = new Connect2(<variable name>);//+ the rest of your arguments

Then you can easily find the value of the name variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.