java - Why should we declare an interface inside a class? -


why should declare interface inside class in java?

for example:

public class genericmodellinker implements imodellinker {    private static final logger log =loggerfactory.getlogger(genericmodellinker.class);   private string joinaspropertyfield;   private boolean joinaslistentry;   private boolean clearlist;   private list<link> joins;    //instead of scalar property   private string uniqueproperty;    public interface link {      object getproperty(iadaptable n);      void setproperty(iadaptable n, object value);    } } 

when want gather fields in object in order emphasize concept, either create external class, or internal (called either nested (static ones) or inner).

if want emphasize fact cooperative class makes strictly no sense (has no use) outside original object use, make nested/inner.

thus, when dealing hierarchy, can describe "nested" interface, implemented wrapping class's subclasses.

in jdk, significant example map.entry inner interface, defined within map interface , implemented various ways hashmap, linkedhashmap etc...

and of course, map.entry needed declared public in order accessible while iterating map wherever code is.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -