Is there any specific reason why interfaces are not compiled into MyInterface.java compiled into .interface file?But any class is compiled into .class file.!
Is there any specific reason why interfaces are not compiled into MyInterface.java compiled into
Share
Java treats interfaces almost like classes, eg they share the same namespace (you can’t have an interface that has the same name as a class) and a compiled interface is almost identical to a compiled abstract class.
So it would not make any sense to store them in a different format or with a different file extension. On the contrary, this would make many things harder. For example, when you load a class or interface by name (Class.forName(“my.class.name”)) Java does not know whether it is a class or an interface. If there would be two different extensions, Java would have try to find a file “my/class/name.class” and then “my/class/name.interface”, instead of only trying the first one.