Created
July 29, 2014 14:02
-
-
Save theomega/ca3fce61dd2552d7af37 to your computer and use it in GitHub Desktop.
Fails because of the life cycle of abstract classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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