함수 gettype()

(Gettype()에서 넘어옴)
24px-Disambig_grey.svg.png 다른 뜻에 대해서는 리눅스 type 문서를 참조하십시오.
.getClass()
gettype
type
typeof
.class

1 C[편집]

16px-Crystal_Clear_app_xmag.svg.png C type() 문서를 참고하십시오.
#include <stdio.h>

#define type(x) _Generic((x),\
        _Bool: "_Bool",                  unsigned char: "unsigned char",          \
         char: "char",                     signed char: "signed char",            \
    short int: "short int",         unsigned short int: "unsigned short int",     \
          int: "int",                     unsigned int: "unsigned int",           \
     long int: "long int",           unsigned long int: "unsigned long int",      \
long long int: "long long int", unsigned long long int: "unsigned long long int", \
        float: "float",                         double: "double",                 \
  long double: "long double",                   char *: "char *",                 \
       void *: "void *",                         int *: "int *",                  \
      default: "unknown")

int main() {
    char ch;
    int a;
    long b;
    char* str;
    char str2[5];
    printf( "%s\n", type(ch) ); // char
    printf( "%s\n", type(a) ); // int
    printf( "%s\n", type(b) ); // long int
    printf( "%s\n", type(str) ); // char *
    printf( "%s\n", type(str2) ); // char *
    return 0;
}

2 Java[편집]

16px-Crystal_Clear_app_xmag.svg.png 자바 getClass() 문서를 참고하십시오.
System.out.println( "hello".getClass() );
// class java.lang.String

Object obj1 = new ArrayList<Object>();
Object obj2 = new HashMap<String,Object>();
System.out.println( obj1.getClass() );
System.out.println( obj2.getClass() );
// class java.util.ArrayList
// class java.util.HashMap

System.out.println( obj1.getClass() == ArrayList.class );
System.out.println( obj1.getClass() == HashMap.class );
System.out.println( obj2.getClass() == ArrayList.class );
System.out.println( obj2.getClass() == HashMap.class );
// true
// false
// false
// true

3 JavaScript[편집]

console.log( typeof [] ); // object
console.log( typeof {} ); // object
console.log( typeof 42 ); // number
console.log( typeof "hello" ); // string
console.log( typeof function(){} ); // function

var func = function() {};
console.log( typeof func ); // function

4 PHP[편집]

16px-Crystal_Clear_app_xmag.svg.png PHP gettype() 문서를 참고하십시오.
echo gettype(123); // integer
echo gettype('123'); // string
echo gettype(array()); // array

5 Python[편집]

16px-Crystal_Clear_app_xmag.svg.png Python type() 문서를 참고하십시오.
Python 3
print(type(123))
print(type('123'))
print(type({}))
print(type([]))
# <class 'int'>
# <class 'str'>
# <class 'dict'>
# <class 'list'>

print(type('안녕'))
print(type(u'안녕'))
# <class 'str'>
# <class 'str'>
→ Python 3는 항상 str = unicode
Python 2
print(type(123))
print(type('123'))
print(type({}))
print(type([]))
# <type 'int'>
# <type 'str'>
# <type 'dict'>
# <type 'list'>

print(type('안녕'))
print(type(u'안녕'))
# <type 'str'>
# <type 'unicode'>

6 Perl[편집]

use Scalar::Util qw(reftype);
my $x = bless {}, 'Wiki::ZetaWiki';
print "type of x: " . ref($x) . "\n";
print "base type of x: " . reftype($x) . "\n";
#type of x: Wiki::ZetaWiki
#base type of x: HASH

7 R[편집]

16px-Crystal_Clear_app_xmag.svg.png R언어 class() 문서를 참고하십시오.
class(42)
#[1] "numeric"
class(TRUE)
#[1] "logical"
class("Hello World")
#[1] "character"

8 Ruby[편집]

puts "123".class
# String
puts 123.class
# Fixnum
puts [].class
# Array
print :hello.class
# Symbol
print Proc.new {}.class
# Proc

9 같이 보기[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}