Say you have a clean class like this:
public class A {
// Stuff
}
And a interface like this:
public interface G {
// Stuff
}
Why am I allowed to do this:
A a = new A();
((G) a) // No errors thrown
I can't understand why it should be possible to cast from the class A to the interface G when they have nothing to do with each other. Can someone please explain this to me?
Follow-up. If I make the following:
public class C implements G {
// Stuff
}
This won't compile:
((C) a)
What is the difference between a class that implements a interface and just the interface?
EDIT: I get a compiler-error saying:
Cannot cast from A to C