Brother Bill (16) [Avatar] Offline
From C# and Java, an interface is a set of method signatures that have to be implemented by a host class.
When I look at the example, it appears that interface Expr is an empty interface.
And then both Num and Sum implement Expr, which has nothing to be implemented.

Why are we doing this? This is very confusing.

The other possibility is that Expr provides two methods that need to be implemented by a host class.
I think that is what you mean.

What is throwing me is that there are no braces wrapping the signatures of Num and Sum.
How do I know when the interface ends?

The syntax is quite strange for someone from C# or Java.
Additional commentary about this would be helpful.

Would Expr be in its own file?

As you can see, this example is very confusing to me.


1. If Expr is in fact an empty interface, explain the value of an empty interface and why it is used.
Dmitry Jemerov (40) [Avatar] Offline
Thanks for the feedback! In the example, `Expr` is indeed an interface which does not define any methods. Such interfaces exist in other languages as well, and are called marker interfaces:

We'll update the text of the book to make this point clearer.
408399 (15) [Avatar] Offline
Hi, Bill,
In Java, a very common example of a Marker Interface is Serializable.