Linked Questions
62 questions linked to/from Java Reflection: How to get the name of a variable?
11 votes
2 answers
22k views
How to get variable name? - java [duplicate]
is possible get variable name? For example: String nameOfCar = "audi"; Now print the result: System.out.println(nameOfCar.getVname???or something similar); Screen: nameOfCar
3 votes
2 answers
14k views
How to get variable name in Java? [duplicate]
Possible Duplicate: Java Reflection: How to get the name of a variable? I've found various discussions on this topic but never any satisfying answer.. A anyVariableName = new A(); How can I get ...
6 votes
4 answers
2k views
Java print string C++ equivalent [duplicate]
What would be the equivalent in java of C++ code: #define printVar(var) cout<<#var<<"="<<var; printing string value and its name .
1 vote
2 answers
4k views
Java: get the variable name from a variable [duplicate]
I'm facing following problem: I have to give names to many thousands of GUI-Elements. Would be nice if it could work a script like: JMenuItem myMenuItem = new JMenuItem(); myMenuItem .setName(this....
0 votes
2 answers
362 views
How do I convert a string representation of an integer to a string in Java? [duplicate]
I'm using a ContentResolver query to get some data from a database in Android. That's not the issue. The method returns string representation of integers, INT TYPE_MAIN = 2 I want to convert that to ...
0 votes
1 answer
172 views
Is there a way to get variable's name in java [duplicate]
String getName(Object o) { //TODO } String object = "i want to get "object" not these words" getName(object); Is it possible the method return "object"? thx
0 votes
1 answer
116 views
how to display variable name dynamic in java [duplicate]
i want to display only the variable name not the value let's say String x='abc'; i want my output to be x notabc don't want to create a code like this System.out.println('x') i want dynamicaly save ...
0 votes
2 answers
124 views
Getting names and or types of variables in java possible? [duplicate]
In my application, i want to print out a variable´s value AND its name, if possible. For example: int testinteger = 0; String type = > type of testinteger? (int); String name = > name of ...
0 votes
0 answers
86 views
Hi can i print variable name? [duplicate]
How can i print variable name in Java? Example: String variableString = "some string"; System.out.println(variableName); Expected result in console: "variableString" I need this for logging for ...
0 votes
0 answers
59 views
How to get the object name in java [duplicate]
I need to get the Object name from .display() function like "faruq unique id is blabla".. Is it possible? Is there any method to make it happen? public class Login { String uniqueID; public ...
0 votes
2 answers
93 views
how do I get randomly, objects name which used one class only? [duplicate]
how do I print objects name randomly, for instance: skeleton, zombie or assassin ? but all of em have used on class only Enemies ? For example, I have: Enemies skeleton = new Enemies(100, 20); ...
0 votes
0 answers
48 views
Returning a variable name for a Rectangle created in Javafx [duplicate]
Is it possible to return the name you gave to a Rectangle object when you created it? For example: Rectangle f = new Rectangle(); f.getName() \\would return "f"
27 votes
3 answers
30k views
How to get the name of a variable in Kotlin?
I have a Kotlin class in my application with a lot of attributes, what I want to build is a method that stores the variable name in a dictionary. The dictionary looks like this: HashMap<String, ...
18 votes
4 answers
61k views
Get the class instance variables and print their values using reflection
I have a 2 POJO classes with getters and setters,now i am trying to get all the class instance variables of that class. I got to know that we can use reflection how to do it? This is my POJO Class ...
14 votes
12 answers
49k views
Looking for an easier way to write debugging print statements in Java
EDIT: I would love to read reactions to Steve Reed's AOP approach. Comments to his answer are encouraged! I'm a novice, and at some point I realized it would be helpful to know the contents of a ...