0.๐Ÿšถ๋“ค์–ด๊ฐ€๋ฉฐ

์Šคํ”„๋ง ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•˜๋ฉฐ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ๋งˆ์ฃผ์ณค์Šต๋‹ˆ๋‹ค.

 

์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์— ๊ด€ํ•œ ์ฝ”๋“œ์ธ๋ฐ ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ์„ ์‚ดํŽด๋ณด๋ฉด AppConfig.class ๋ผ๋Š” ์ธ์ž๋ฅผ ๋„˜๊ฒจ์ฃผ๊ณ  ์žˆ๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

์ด๋•Œ AppConfig.class๊ฐ€ ๋ญ์ง€..? ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์‚ฌ๊ณ ๊ณผ์ •์„.. ๊ฑฐ์ณ๊ฐ”์Šต๋‹ˆ๋‹ค.

  1. AppConfig.class ๋ผ๊ณ  ์“ฐ๋Š” ๊ฑธ ๋ณด๋‹ˆ AppConfig์˜ static ๋ณ€์ˆ˜์ธ๊ฐ€?
  2. AppConfig๋Š” ๋‚ด๊ฐ€ ๋งŒ๋“  ํด๋ž˜์Šค์ธ๋ฐ ๊ทธ๋Ÿผ ๋ถ€๋ชจ ํด๋ž˜์Šค์ธ Object ํด๋ž˜์Šค์— ์ €๋Ÿฐ static ๋ณ€์ˆ˜๊ฐ€ ์žˆ์—ˆ๋˜๊ฐ€?
  3. Object ํด๋ž˜์Šค์— ์ €๋Ÿฐ static ๋ณ€์ˆ˜๊ฐ€ ์—†๋Š”๋ฐ..?


1.Class Literal

๊ด€๋ จ๋œ ๋‚ด์šฉ์„ ๊ฒ€์ƒ‰ํ•˜๋‹ค๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์€ ํ‚ค์›Œ๋“œ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์—ˆ๊ณ , Oracle docs์—๋Š” Class Literal์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค๋ช…ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ Class Literal์˜ ์˜ˆ์‹œ๋กœ๋Š” String.class, Integer.class๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void, followed by a '.' and the token class.

A class literal evaluates to the Class object for the named type (or for void) as defined by the defining class loader of the class of the current instance.

์œ„ ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๋ฉด .class๋Š” static ๋ณ€์ˆ˜๊ฐ™์€ ๊ฒƒ์ด ์•„๋‹ˆ๊ณ  ์ž๋ฐ”์˜ token ์ž„์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ, ClassName.class์˜ ํƒ€์ž…์€ Class ํด๋ž˜์Šค๋ผ๊ณ  ํ•˜๋Š”๋ฐ์š”. ์ด์— Class ํด๋ž˜์Šค๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๊ฐ„๋‹จํžˆ ์•Œ์•„๋ณด๊ณ  ๊ธ€์„ ๋งˆ์น˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

# Class ํด๋ž˜์Šค

์ž๋ฐ”์˜ ๋ชจ๋“  ํด๋ž˜์Šค๋Š” ์ปดํŒŒ์ผ ํ›„ class ํŒŒ์ผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. classํŒŒ์ผ์—๋Š” ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ, ์ƒ์„ฑ์ž ๋“ฑ๋“ฑ ๊ฐ์ฒด์˜ ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ์ฃ ! ์ด๋•Œ Class ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ classํŒŒ์ผ์— ์žˆ๋Š” ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์•„๋ž˜์™€ ๊ฐ™์ด ๋ง์ด์ฃ !

Class<String> class1 = String.class;

2.๐Ÿ’จ๋‚˜๊ฐ€๋ฉฐ

๊ฒฐ๋ก ์ ์œผ๋กœ ์ฒ˜์Œ ๋ณด์•˜๋˜ ์ฝ”๋“œ๋Š” ์ธ์ž์— AppConfig ํด๋ž˜์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋„˜๊ฒจ์ฃผ๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

 

 

 

๋ฐ˜์‘ํ˜•
๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค!