This is probably a dumb question so bear with me. Why doesn't this work?
static final Comparator<Product> SENIORITY_ORDER = new Comparator<Product>();
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at OrderProcessor.main(OrderProcessor.java:178)
This works:
static final Comparator<Product> SENIORITY_ORDER = new Comparator<Product>(){
public int compare(Product e1, Product e2) {
return 1;
}
};
I Just had it return 1 just for testing. The compare method has nothing to do with my question. I just don't understand why the top code doesn't work and the bottom code does work.?
Referring to the bottom code, is that what an anonymous inner class is?
If yes, then why do I have to use an anon class to instantiate the Comparator object?
Thanks