Close

Java Reflection - Class.isMemberClass() Examples

Code Snippets Java Reflection Java Java API 


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 isMemberClass()

Returns true if and only if the underlying class is a member class.

Examples


package com.logicbig.example.clazz;

public class IsMemberClassExample {

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

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

private static class MyStaticClass {}

private class MyClass {}

}

Output

true
true




package com.logicbig.example.clazz;

import java.io.Serializable;

public class IsMemberClassExample2 {

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

//anonymous class
b = new Serializable() {}.getClass().isMemberClass();
System.out.println(b);
}
}

Output

false
false




See Also