The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex
Use Modifier.isStatic(method.getModifiers()).
ReplyDelete/**
* Returns the public static methods of a class or interface,
* including those declared in super classes and interfaces.
*/
public static List<Method> getStaticMethods(Class<?> clazz) {
List<Method> methods = new ArrayList<Method>();
for (Method method : clazz.getMethods()) {
if (Modifier.isStatic(method.getModifiers())) {
methods.add(method);
}
}
return Collections.unmodifiableList(methods);
}
Note: This method is actually dangerous from a security standpoint. Class.getMethods "bypass[es] SecurityManager checks depending on the immediate caller's class loader" (see section 6 of the Java secure coding guidelines).
Disclaimer: Not tested or even compiler.
Note Modifier should be used with care. Flags represented as ints are not type safe. A common mistake is to test a modifier flag on a type of reflection object that it does not apply to. It may be the case that a flag in the same position is set to denote some other information.
You can get the static methods like this:
ReplyDeletefor (Method m : MyClass.class.getMethods()) {
if (Modifier.isStatic(m.getModifiers()))
System.out.println("Static Method: " + m.getName());
}
To flesh out the previous (correct) answer, here is a full code snippet which does what you want (exceptions ignored):
ReplyDeletepublic Method[] getStatics(Class<?> c) {
Method[] all = c.getDeclaredMethods()
List<Method> back = new ArrayList<Method>();
for (Method m : all) {
if (Modifier.isStatic(m.getModifiers())) {
back.add(m);
}
}
return back.toArray(new Method[back.size()]);
}