Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java print string C++ equivalent [duplicate]

Tags:

java

c++

string

What would be the equivalent in java of C++ code:

#define printVar(var) cout<<#var<<"="<<var;

printing string value and its name .

like image 861
repo Avatar asked May 19 '14 12:05

repo


1 Answers

You can print the variable name since Java 8 version: Java Reflection: How to get the name of a variable?

You can print the value using something like: System.out.println(String.valueOf(var));

Through Java reflection you can get more information from a variable, such as class name, package name, class attributes, etc...

like image 145
carlosvin Avatar answered Sep 18 '22 10:09

carlosvin