Logo

Programming-Idioms

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.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
(type x)
#include <typeinfo>
std::cout<<typeid(x).name();
System.Console.WriteLine( x.GetType() );
import std.stdio: writeln;
writeln(typeid(x));
print(x.runtimeType);
[{_, type} | _] = IEx.Info.info(x)
type
fmt.Printf("%T", x)
import "reflect"
fmt.Println(reflect.TypeOf(x))
import Data.Dynamic
print (dynTypeRep (toDyn x))
console.log (x == null ? x + '' : x.constructor.name);
console.log(typeof x);
System.out.println(((Object)x).getClass().getName());
import static java.lang.System.out;
var x = "abc";
out.println(x.getClass().getSimpleName());
println(x::class.simpleName)
(describe x)
print(type(x))
echo is_object($x) ? get_class($x) : gettype($x);
{$mode objfpc}{$H+}
{$ModeSwitch ImplicitFunctionSpecialization }
 
generic procedure PrintTypeOfX<T>(const X: T);
var
  tk: TTypeKind;
begin
  tk := System.GetTypeKind(X);
  writeln(tk);
end;
print ref($x)||"SCALAR", "\n";
print(x.__class__)
print(type(x))
puts x.class
#![feature(core_intrinsics)]
fn type_of<T>(_: &T) -> &'static str {
    std::intrinsics::type_name::<T>()
}

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