Android examples for java.lang.reflect:Nested Class
get Enclosing Instance Name
//package com.java2s; public class Main { public static String getEnclosingInstanceName(Object innerInstance) { int depth = -1; Class<?> enclosing = innerInstance.getClass().getEnclosingClass(); while (enclosing != null) { ++depth;//w w w. j a va 2 s .c om enclosing = enclosing.getEnclosingClass(); } return (depth == -1) ? null : "this$" + depth; } }