The following program is valid Java, even though the Runnable
on line 1 is a completely different symbol than Runnable
on line 3:
public class Refrigerator implements Runnable {
public void run() {
new Runnable().freeze();
}
public class Runnable {
void freeze() {
System.out.println("cold and refreshing");
}
}
public static void main(String[] args) {
new Thread(new Refrigerator()).start();
}
}
I'm not quite sure if this is shadowing, obscuring or hiding, but it's certainly not good. Writing a compiler must be pretty difficult!