File tree Expand file tree Collapse file tree
main/java/de/codecentric/java8examples/defaultmethods
test/java/de/codecentric/java8examples/defaultmethods Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package de .codecentric .java8examples .defaultmethods ;
2+
3+ /**
4+ * A greeting service implementation that inherits {@link #greet()} from two unrelated interfaces. It has to provide
5+ * an implementation for {@code greet()}.
6+ */
7+ public class CombinedGreetingService implements GreetingService , AlternativeGreetingService {
8+
9+ /**
10+ * An implementation of the {@code greet()} method which is defined in both, {@link GreetingService} and
11+ * {@link AlternativeGreetingService}. This implementation simply delegates to the default {@code greet()}
12+ * implementation of the {@code GreetingService} interface
13+ *
14+ * @return the result of calling {@link GreetingService#greet()}.
15+ */
16+ @ Override
17+ public String greet () {
18+ return GreetingService .super .greet ();
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -23,4 +23,10 @@ public void greetFromExtended() throws Exception {
2323 public void greetFromDerived () throws Exception {
2424 assertEquals ("Salut le monde!" , new DerivedGreetingService ().greet ());
2525 }
26+
27+ @ Test
28+ public void testName () throws Exception {
29+ assertEquals ("Hello World!" , new CombinedGreetingService ().greet ());
30+
31+ }
2632}
You can’t perform that action at this time.
0 commit comments