๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Java] Class.java public boolean isAssignableFrom(Class<?> cls)

java.lang.Class<T>

 

public boolean isAssignableFrom(Class<?> cls)

 

ํ•ด๋‹น ํด๋ž˜์Šค(๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค)์˜ Class object ๊ฐ€ ํŒŒ๋ผ๋ฏธํ„ฐ cls(ํด๋ž˜์Šค ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค) Class์™€ ๋™์ผํ•˜๊ฑฐ๋‚˜ cls์˜ superclass ๋˜๋Š” superinterface์ผ ๊ฒฝ์šฐ true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์•„๋‹ ๊ฒฝ์šฐ false ๋ฐ˜ํ™˜.

 

์ฆ‰, ํ•ด๋‹น ํด๋ž˜์Šค/์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ํด๋ž˜์Šค/์ธํ„ฐํŽ˜์Šค์™€ ๊ฐ™๊ฑฐ๋‚˜, ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ํด๋ž˜์Šค์˜ ๋ถ€๋ชจ ํด๋ž˜์Šค/์ธํ„ฐํŽ˜์ด์Šค์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๋ฐ˜ํ™˜. 

 

{์ž์‹ ํด๋ž˜์Šค}.isAssignableFrom({์ž์‹ ํด๋ž˜์Šค}) -> true

{์ž์‹ ํด๋ž˜์Šค}.isAssignableFrom({๋ถ€๋ชจ ํด๋ž˜์Šค}) -> false

{๋ถ€๋ชจ ํด๋ž˜์Šค}.isAssignableFrom({์ž์‹ ํด๋ž˜์Šค}) -> false

 

{CharSequence ํด๋ž˜์Šค}.isAssignableFrom({String ํด๋ž˜์Šค})  -> true
{String ํด๋ž˜์Šค}.isAssignableFrom({CharSequence ํด๋ž˜์Šค}) -> false

 

docs.oracle.com/javase/8/docs/api/java/lang/Class.html#isAssignableFrom-java.lang.Class-

 

Class (Java Platform SE 8 )

Determines if the specified Class object represents a primitive type. There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types tha

docs.oracle.com


๋ฐœ๋ฒˆ์—ญ์œผ๋กœ ๊ณ ๊ตฐ๋ถ„ํˆฌํ•ด์„œ ์–ด๋–ป๊ฒŒ ์ดํ•ด๋Š” ํ–ˆ๋‹ค.