Created
May 11, 2016 21:34
-
-
Save nipafx/264e9a705cba15766d66eed4d3549389 to your computer and use it in GitHub Desktop.
Demonstrating Visibility
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
package org.codefx.lab.visibility; | |
class PackagePrivate { | |
public String publicToUpper(String s) { | |
return s.toUpperCase(); | |
} | |
String packageToUpper(String s) { | |
return s.toUpperCase(); | |
} | |
} |
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
package org.codefx.lab.visibility; | |
public class Public extends PackagePrivate { } |
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
package org.codefx.lab.visibility.not; | |
import org.codefx.lab.visibility.Public; | |
import org.junit.Test; | |
import java.util.stream.Stream; | |
public class VisibilityTest { | |
@Test | |
public void toUpper() throws Exception { | |
Public p = new Public(); | |
Stream.of("a", "b", "c") | |
.map(p::publicToUpper) | |
// next line is a compile error: | |
// "The type org.codefx.lab.visibility.Public does not define packageToUpper(java.lang.String) | |
// that is applicable here" | |
// commenting it out makes the code compile and run | |
.map(p::packageToUpper) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This reproduces the error: