Skip to content

Instantly share code, notes, and snippets.

@theomega
Created July 29, 2014 14:02
Show Gist options
  • Save theomega/ca3fce61dd2552d7af37 to your computer and use it in GitHub Desktop.
Save theomega/ca3fce61dd2552d7af37 to your computer and use it in GitHub Desktop.
Fails because of the life cycle of abstract classes
public class AnonInnerClass {
private final List<Job> jobsCache = new ArrayList<>();
private Class<? extends Job> getClass(final String s) {
final Job job = new Job() {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println(s);
}
};
jobsCache.add(job);
return job.getClass();
}
private Job constructInstance(Class<? extends Job> jobClass) {
try {
return jobClass.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new IllegalArgumentException(e);
}
}
@Test
public void test() throws JobExecutionException {
constructInstance(getClass("One")).execute(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment