- 다른 뜻에 대해서는 리눅스 type 문서를 참조하십시오.
1 개요[ | ]
- .getClass()
- gettype
- type
- typeof
- .class
- 자료형을 확인하는 함수
2 C[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
C
Copy
#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 *
}
Loading
3 Go[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
Go
Copy
package main
import (
"fmt"
"reflect"
)
func main() {
fmt.Println(reflect.TypeOf(123)) // int
fmt.Println(reflect.TypeOf(123.45)) // float64
fmt.Println(reflect.TypeOf("hello")) // string
fmt.Println(reflect.TypeOf(true)) // bool
fmt.Println(reflect.TypeOf(false)) // bool
fmt.Println(reflect.TypeOf(nil)) // <nil>
}
Loading
4 Java[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
Java
Copy
import java.util.ArrayList;
import java.util.HashMap;
class MyClass{public static void main(String[] args){
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() ); // class java.util.ArrayList
System.out.println( obj2.getClass() ); // class java.util.HashMap
System.out.println( obj1.getClass() == ArrayList.class ); // true
System.out.println( obj1.getClass() == HashMap.class ); // false
System.out.println( obj2.getClass() == ArrayList.class ); // false
System.out.println( obj2.getClass() == HashMap.class ); // true
}}
Loading
5 JavaScript[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
JavaScript
Copy
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
▶ | object |
▶ | object |
▶ | number |
▶ | string |
▶ | function |
▶ | function |
6 PHP[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
PHP
Copy
echo gettype(123) ."\n"; # integer
echo gettype('123')."\n"; # string
echo gettype([]) ."\n"; # array
Loading
7 Python[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
Python 3
Python
Copy
print(type(123)) # <class 'int'>
print(type('123')) # <class 'str'>
print(type({})) # <class 'dict'>
print(type([])) # <class 'list'>
print(type('안녕')) # <class 'str'>
print(type(u'안녕')) # <class 'str'>
Loading
- → Python 3는 항상 str = unicode
Python 2
Python
Copy
print(type(123)) # <type 'int'>
print(type('123')) # <type 'str'>
print(type({})) # <type 'dict'>
print(type([])) # <type 'list'>
print(type('안녕')) # <type 'str'>
print(type(u'안녕')) # <type 'unicode'>
8 Perl[ | ]
Perl
Copy
use Scalar::Util qw(reftype);
my $x = bless {}, 'Wiki::ZetaWiki';
print "type of x: " . ref($x) . "\n"; # type of x: Wiki::ZetaWiki
print "base type of x: " . reftype($x) . "\n"; # base type of x: HASH
Loading
9 R[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
R
Copy
class(42) #[1] "numeric"
class(TRUE) #[1] "logical"
class("Hello World") #[1] "character"
Loading
10 Ruby[ | ]
![](https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/24px-Crystal_Clear_app_xmag.svg.png 1.5x, https://z-images.s3.amazonaws.com/thumb/e/ec/Crystal_Clear_app_xmag.svg/32px-Crystal_Clear_app_xmag.svg.png 2x)
Ruby
Copy
puts "123".class # String
puts 123.class # Integer
puts 123.45.class # Float
puts [].class # Array
puts :hello.class # Symbol
puts Proc.new {}.class # Proc
Loading