« |
Main
| »
December 26, 2009
Here are questions 3 and 4 in the java-question series:
Question 3: Will this compile? If not, why? If so, why would I ask this question?
import java.awt.*;
import java.util.*;
enum TrafficLight {
GREEN(Color.green),
YELLOW(Color.yellow),
RED(Color.red);
private final static Map<Color,TrafficLight>
INSTANCES = new HashMap<Color,TrafficLight>();
private final Color c;
private TrafficLight(Color c) {
this.c = c;
INSTANCES.put(c,this);
}
public static TrafficLight getInstance(Color c) {
return INSTANCES.get(c);
}
}
Question 4: If you answered No to the first question, what should be done with the person who designed enums to make this so?
Answer 4: Drug out to the barn and shot.
Posted by jeff at December 26, 2009 01:13 PM