Java tutorial
//package com.java2s; import java.lang.reflect.*; public class Main { public static String isLocalType(Class<?> type, boolean allowNonStatic) { /* As per [JACKSON-187], GAE seems to throw SecurityExceptions * here and there... and GAE itself has a bug, too * (see []). Bah. So we need to catch some wayward exceptions on GAE */ try { // one more: method locals, anonymous, are not good: if (type.getEnclosingMethod() != null) { return "local/anonymous"; } /* But how about non-static inner classes? Can't construct * easily (theoretically, we could try to check if parent * happens to be enclosing... but that gets convoluted) */ if (!allowNonStatic) { if (type.getEnclosingClass() != null) { if (!Modifier.isStatic(type.getModifiers())) { return "non-static member class"; } } } } catch (SecurityException e) { } catch (NullPointerException e) { } return null; } }