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

Idiom #94 Print type of 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 std.stdio: writeln;
writeln(typeid(x));
System.Console.WriteLine(x.GetType());
print(x.runtimeType);
fmt.Printf("%T", x)
import "reflect"
fmt.Println(reflect.TypeOf(x))
import Data.Dynamic
print (dynTypeRep (toDyn x))
int a = 0;
String b = "str";
System.out.println(((Object)a).getClass().getName());
System.out.println(b.getClass().getName());
print(type(x))
echo is_object($x) ? get_class($x):gettype($x);
print ref($x)||"SCALAR", "\n";
print(x.__class__)
print(type(x))
puts x.class
#![feature(core_intrinsics)]
fn type_of<T>(_: &T) -> &'static str {
    unsafe { std::intrinsics::type_name::<T>() }
}

println!("{}", type_of(&x));

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org