Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #94 Print the type of a variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

import static java.lang.System.out;
var x = "abc";
out.println(x.getClass().getSimpleName());

All bindings in Java are considered static; there is no re-declaration, only re-assignment.
System.out.println(((Object)x).getClass().getName());
(type x)

New implementation...
< >
programming-idioms.org