강의

멘토링

커뮤니티

Inflearn Community Q&A

jjc55242869's profile image
jjc55242869

asked

More Java, different ways to manipulate code

Reflection API Part 2: Modifying or Executing Class Information

new 와 constructor.newInstance();의 차이

Written on

·

656

0

Class<?> bookClass = Class.forName("thejava.reflection.MyBook");

Constructor<?> constructor = bookClass.getConstructor(null);//인자 없는 생성자를 넘겨받아서

MyBook book = (MyBook) constructor.newInstance();

이렇게 인스턴스를 생성하는것과

new MyBook()이랑은 무슨차이죠?

둘다 출력해보면

thejava.reflection.MyBook@~ 로 나오는데.. 같은건가요?

javaspringJPA

Answer

This question is waiting for answers
Be the first to answer!
jjc55242869's profile image
jjc55242869

asked

Ask a question