Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Created December 17, 2013 16:41
Show Gist options
  • Select an option

  • Save benwaffle/8008028 to your computer and use it in GitHub Desktop.

Select an option

Save benwaffle/8008028 to your computer and use it in GitHub Desktop.
Create an instance of the Math class
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