How to write our own marker interface in Java?

前端 未结 6 854
遇见更好的自我
遇见更好的自我 2021-02-04 06:15

I know marker interface in java. It is used to define a specific behaviour about a class. For example, Serializable interface has the specific ability to store an object into by

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 06:53

    As far as I know marker interfaces get their behaviour by "utility" classes. For example if you have read the Design Patterns book by the Gang of Four, you have behaviour of a class tagged with a marker interface defined in another class.

    For example you have a marker interface "Saveable". You have a process that traverses all classes implementing this interface (via reflection) and then does save operation on it.

提交回复
热议问题