Compare object name (reference name) with a string
java
Solution
That can't be done directly in Java. Variable names are merely a convenience for the programmer and are not even kept track of after your code is compiled. You can instead use a `Map` that maps string identifiers to their corresponding objects. Or you can add a `name` field to your class which holds a string (`"obj"` in your example):
ClassName obj = new ClassName("obj");
if (obj.getName().equals(...))
...
(Note that I've assumed a more standard naming convention.)
Problem
How to compare name of an object to a string in Java? For example: ``` class_name obj = new class_name(); ``` and I want to compare object name `obj` with a string. What is the correct way to do that?