What is the difference between getDeclaredConstructors and getConstructors in the Class API?

前端 未结 4 1520
遥遥无期
遥遥无期 2021-01-30 19:50

I notice that in the Java Reflection API there are two different methods for invoking constructors: the getDeclaredConstructors/getConstructors method.

4条回答
  •  灰色年华
    2021-01-30 20:25

    I use getDeclaredConstructors to create a factory of classes whose constructor is private to avoid that the "users" of my system can create these classes directly without using the factory. I find this method quite useful.

提交回复
热议问题