Close

Java Reflection - Class.isLocalClass() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public boolean isLocalClass()
Returns:
true if and only if this class is a local class.


Examples


package com.logicbig.example.clazz;

public class IsLocalClassExample {

public static void main(String... args) {
class MyLocalClass {}
boolean b = MyLocalClass.class.isLocalClass();
System.out.println(b);
}
}

Output

true




package com.logicbig.example.clazz;

public class IsLocalClassExample2 {

public static void main(String... args) {
Object o = new Object() {};//anonymous class
boolean b = o.getClass().isLocalClass();
System.out.println(b);

b = o.getClass().isAnonymousClass();
System.out.println(b);
}
}

Output

false
true




package com.logicbig.example.clazz;

public class IsLocalClassExample3 {

public static void main(String... args) {
boolean b = MyNestedClass.class.isLocalClass();
System.out.println(b);

b = MyNestedClass.class.isMemberClass();
System.out.println(b);
}

private static final class MyNestedClass {}
}

Output

false
true




See Also