What does the definition of constants in the interface mean?

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 class C implements I

Since constants are public and static, can I access them directly through I?

+5
source share
3 answers

(anti-) , I.. , import static , . , - - , ,

ConstantInterfaceWithNoMethods m = new ClassImplementingThatInterface;

if (m instanceof ConstantInterfaceWithNoMethods)

.

, !

+10

Java, . , , enum .

, , .

+5

Generally, you do not need to. One reason may be that the interface Iis a "marker interface".

0
source

All Articles