The class itself has an outer class package.
getModifiers() A value of 8 , which according to the comments: static, package private .
Its static (why?). I cannot reference Main.this from within an anonymous class in Main .
Its package private . However, the access level of an anonymous class does not even mean much, because you cannot use its type at compile time, like a regular class.
https://ideone.com/vzbdQ5
// JDK 8 import java.lang.reflect.Modifier; public class Main { public static void main(String[] args) throws Exception { Class anon = new Main() {}.getClass(); System.out.println("Name:" + anon.getName()); // Main$1 System.out.println("Anonymous:" + anon.isAnonymousClass()); // true System.out.println("Package:" + anon.getPackage()); // null System.out.println("public ? " + Modifier.isPublic(anon.getModifiers())); // false System.out.println("private ? " + Modifier.isPrivate(anon.getModifiers())); // false System.out.println("protected ? " + Modifier.isProtected(anon.getModifiers())); // false assert anon.newInstance() instanceof Main; assert Class.forName(anon.getName()).newInstance() instanceof Main; } }
source share