-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove bridge methods from interfaces, fixes #13
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
end-to-end-tests/src/test/java/net/orfjackal/retrolambda/test/DefaultMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright © 2013-2014 Esko Luontola <www.orfjackal.net> | ||
// This software is released under the Apache License 2.0. | ||
// The license text is at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package net.orfjackal.retrolambda.test; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class DefaultMethodsTest { | ||
|
||
/** | ||
* JDK 8 adds a bridge method to an interface when it overrides a method | ||
* from the parent interface and refines its return type. This uses Java 8's | ||
* default methods feature, which won't work on Java 7 and below, so we have | ||
* to remove it for it - this makes the bytecode same as what JDK 7 produces. | ||
*/ | ||
@Test | ||
public void will_remove_non_abstract_methods_from_interfaces() { | ||
class Foo implements Child { | ||
@Override | ||
public String foo() { | ||
return "foo"; | ||
} | ||
} | ||
assertThat(new Foo().foo(), is("foo")); | ||
} | ||
|
||
public interface Parent { | ||
Object foo(); | ||
} | ||
|
||
public interface Child extends Parent { | ||
String foo(); // refined return type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters