/** * @author lautturi.com * Java example: get the type of a variable in java */ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.*; public class Lautturi { public static void main(String[] args) throws FileNotFoundException { String str = "hello lautturi"; String varType = ((Object) str).getClass().getName(); // String varType = ((Object) str).getClass().getSimpleName(); System.out.println(varType); } }
output:
java.lang.String OR String