public static Class<?> getSubclassInScope(final Class<?> scopeClass) {
		final String callerClass = Thread.currentThread().getStackTrace()[3].getClassName();
		try {
			final Class<?> candidateClass = Class.forName(callerClass, false, Thread.currentThread().getContextClassLoader());
			if(!scopeClass.isAssignableFrom(candidateClass)) {
				return null;
			}
			return candidateClass;
		} catch (final ClassNotFoundException e) {
			throw new IllegalStateException("The class should always exist",e);
		}
	}
public static Class<?> getSubclassInScope(final Class<?> scopeClass) {
		final String callerClass = Thread.currentThread().getStackTrace()[3].getClassName();
		try {
			final Class<?> candidateClass = Class.forName(callerClass, false, Thread.currentThread().getContextClassLoader());
			if(!scopeClass.isAssignableFrom(candidateClass)) {
				return null;
			}
			return candidateClass;
		} catch (final ClassNotFoundException e) {
			throw new IllegalStateException("The class should always exist",e);
		}
	}
public static Class < ? > getSubclassInScope ( final Class < ? > scopeClass ) { final String callerClass = Thread . currentThread ( ) . getStackTrace ( ) [ 3 ] . getClassName ( ) ; try { final Class < ? > candidateClass = Class . forName ( callerClass , false , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; if ( ! scopeClass . isAssignableFrom ( candidateClass ) ) { return null ; } return candidateClass ; } catch ( final ClassNotFoundException e ) { throw new IllegalStateException ( "The class should always exist" , e ) ; } }
TODO: Relax this constraint, it should be possible to do it from
named-inner classes.

@param scopeClass
the parent class from which to retrieve the subclass in the
scope.

@return the subclass of the specified that is within the scope if found,
{@code null} otherwise.
TODO : Relax this constraint it should be possible to do it from named - inner classes .