public static Class<?> lenientClassForName(String className) throws ClassNotFoundException {
    try {
      // TODO: consider whether any control over class loader is really needed here
      // (forName(className, true, Thread.currentThread().getContextClassLoader())?)
      return Class.forName(className);
    } catch (ClassNotFoundException ignored) {
      // try replacing the last dot with a $, in case that helps
      // example: tutorial.Tutorial.Benchmark1 becomes tutorial.Tutorial$Benchmark1
      // amusingly, the $ character means three different things in this one line alone
      String newName = className.replaceFirst("\\.([^.]+)$", "\\$$1");
      return Class.forName(newName);
    }
  }
public static Class < ? > lenientClassForName ( String className ) throws ClassNotFoundException { try { return Class . forName ( className ) ; } catch ( ClassNotFoundException ignored ) { String newName = className . replaceFirst ( "\\.([^.]+)$" , "\\$$1" ) ; return Class . forName ( newName ) ; } }
fails try replacing the last . with $.