I know that in Java, someone can include constants inside interfaces by declaring them public static final. However, suppose I have an interface called called Ithat contains only public static final constants and no method signatures and a class called C. Why do I want to implement me in C? then why should I do the following:
public static final
I
C
public class C implements I
Since constants are public and static, can I access them directly through I?
(anti-) , I.. , import static , . , - - , ,
I.
import static
ConstantInterfaceWithNoMethods m = new ClassImplementingThatInterface;
if (m instanceof ConstantInterfaceWithNoMethods)
.
, !
Java, . , , enum .
enum
, , .
Generally, you do not need to. One reason may be that the interface Iis a "marker interface".