2

It's a rather theoretical question, but what kind of interfaces does java have? For example, I know two of them:

  • marker interfaces (e.g. Serializable, no methods defined, is similar to class-level annotations)
  • functional interfaces (e.g. Runnable, defines only one method)

Are there any more?

UPDATE

It might have been a better way to ask the question like this: in java, what do you use interfaces for? Besides the following ones:

  • defining a "contract" for implementing classes ("standard" way)
  • marking classes (e.g. for the JVM)
  • using for lambda expressions
  • using to implement "traits"

UPDATE

I'm not looking for the answer to "why/when/how to use interfaces for defining contracts" (e.g. the "standard" way, how interfaces are ment to be used initially); I'm looking for any other ways how people are using it (e.g. for marking, traits, etc.)

krisy
  • 1,508
  • 1
  • 14
  • 32
  • An interface is a collection of 0 or more predefined method declarations for you to implement to satisfy the interface.You can find some more information [here](https://docs.oracle.com/javase/tutorial/java/concepts/interface.html). – Turing85 Jan 01 '16 at 15:00
  • 1
    I've checked the link, but did not see anything about marker or functional interfaces, or generally, about the different types of interfaces ... – krisy Jan 01 '16 at 15:06
  • 1
    Fundamentallym they are no differences. Marker-interfaces are interfaces without any methods declared, i.e. they only "mark" some functionality (like `Serializable` or `Cloneable`). Each interface defining only one method can be seen as a functional interface, i.e. it can be implemented with a lambda-expression (you can find more about lambdas and functional interfaces [here](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html)). You could split up interfaces further, but this leads to design patterns and is most probably not, what you are looking / asking for. – Turing85 Jan 01 '16 at 15:16
  • There are nice dogs, brown dogs, and playful dogs. Are there any more? Same for interfaces. "marker" and "functional" are just adjectives, not categories in any standard taxonomy. – Matt Timmermans Jan 01 '16 at 16:13
  • Updated my question to clarify – krisy Jan 01 '16 at 19:02

1 Answers1

0

There are many interfaces in java for different things. Some for just marking other classes like for example ´Serializable´

Really listing them doesn't make sense as you will often learn them on a need to know basis when you need to work with an interface to accomplish something.

Read more about interfaces here.

Czarek
  • 597
  • 1
  • 10
  • 20