Created
December 17, 2013 16:41
-
-
Save benwaffle/8008028 to your computer and use it in GitHub Desktop.
Create an instance of the Math class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.lang.reflect.Constructor; | |
| import java.lang.reflect.InvocationTargetException; | |
| public class MathReflection { | |
| public static void main(String[] args) throws SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException { | |
| Constructor<?> ctor = Math.class.getDeclaredConstructors()[0]; | |
| ctor.setAccessible(true); | |
| Math mathinstance = (Math) ctor.newInstance(); | |
| System.out.println(mathinstance); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment