How do you know a variable type in java?

Miguel Ribeiro picture Miguel Ribeiro · Apr 20, 2010 · Viewed 353.1k times · Source

Let's say I declare a variable:

String a = "test";

And I want to know what type it is, i.e., the output should be java.lang.String How do I do this?

Answer

Martin picture Martin · Apr 20, 2010
a.getClass().getName()