Hi friends , Is it possible to make a newInstance() of a class which doesn't have a default constructor?(java + reflection)
I want to invoke the methods of Math class but it is not possible because the constructor of this class is private!and I cannot make a newInstance even when I use getDeclaredConstructors my code throw this exception :" can not access a member of class java.lang.Math with modifiers "private" ".what can I do to solve this problem?
You cannot create an instance of Math because it has no constructors, default or otherwise, it consists of only methods. Basically it is a collection of function calls and not a collection of "types" that define a larger object. http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html
thanks!
Join our real-time social learning platform and learn together with your friends!