Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2012 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4035987 to your computer and use it in GitHub Desktop.
Save anonymous/4035987 to your computer and use it in GitHub Desktop.
package com.flurry.example;
public interface IBar {
public abstract String getName();
}
public interface IFoo {
public boolean isTransient();
}
public abstract class AFoo implements IFoo
{
private long fId;
public long getId()
{
return fId;
}
@Override
public boolean isTransient()
{
return fId == 0;
}
}
public class Thing extends AFoo implements IBar
{
@Override
public String getName() {
return "Thing";
}
}
public abstract class Parameterized<T extends AFoo & IBar> {
public final String name;
public final static Map<String, Parameterized<?>> entities = new HashMap<String,Parameterized<?>>();
public abstract List<T> getByType();
private Parameterized(String name) {
this.name = name;
entities.put(name, this);
}
public static final Parameterized<Thing> THING = new Parameterized<Thing>("thing") {
@Override
public List<Thing> getByType() {
return new ArrayList<Thing>();
}
};
}
public class CompileMe<T extends AFoo & IBar> {
private Parameterized<T> parameterized;
public void doSomething() throws Exception {
for (T entity : parameterized.getByType()) {
if (parameterized == Parameterized.THING)
{
System.out.println(entity.getId());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment