Skip to content

Commit

Permalink
Test status quo for void method references passed to assertDoesNotThr…
Browse files Browse the repository at this point in the history
…ow()

Issue: #1576
  • Loading branch information
sbrannen committed Sep 7, 2018
1 parent ff968ed commit f445e5c
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ void assertDoesNotThrowWithFutureMethodReference() {
assertEquals("foo", result);
}

@Test
void assertDoesNotThrowWithMethodReferenceForVoidReturnType() {
var foo = new Foo();

// Note: the following does not compile since the compiler cannot properly
// perform type inference for a method reference for an overloaded method
// that has a void return type such as Foo.overloaded(...)
//
// assertDoesNotThrow(foo::overloaded);

// Current compiler's type inference
assertDoesNotThrow(foo::normalMethod);

// Explicitly as an Executable
assertDoesNotThrow((Executable) foo::normalMethod);
assertDoesNotThrow((Executable) foo::overloaded);
}

// --- executable ----------------------------------------------------------

@Test
Expand Down Expand Up @@ -221,4 +239,19 @@ void assertDoesNotThrowWithSupplierThatThrowsAnExceptionWithMessageSupplier() {
}
}

// -------------------------------------------------------------------------

private static class Foo {

void normalMethod() {
}

void overloaded() {
}

void overloaded(int i) {
}

}

}

0 comments on commit f445e5c

Please sign in to comment.