Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- File[] files = new File("C:").listFiles(File::isHidden); // OK
- test(MyCass::mymethod); // Cannot make a static reference to the non-static method
- }
- static interface FunctionalInterface{
- boolean function(String file);
- }
- class MyCass{
- boolean mymethod(String input){
- return true;
- }
- }
- // HELPER
- public static void test(FunctionalInterface functionalInterface){}
- listFiles(File::isHidden)
- listFiles(f -> f.isHidden())
- MyCass myCass = new MyCass(); // the instance
- test(myCass::mymethod); // pass a non-static method reference
- test(new MyCass()::mymethod);
- class MyCass{
- static boolean mymethod(String input){
- return true;
- }
- }
- new FunctionalInterface{
- boolean function(String file){
- return MyClass.mymethod(file);
- }
- }
- new FunctionalInterface{
- boolean function(String file){
- return _missing_object_.mymethod(); # mymethod is not static
- }
- }
- test(MyCass::mymethod); // Cannot make a static reference to the non-static method
- test(v -> MyCass.mymethod(v)); // static access
- class MyCass {
- static boolean mymethod(String input) {
- return true;
- }
- }
- public static void main(String[] args) {
- MyCass myCass = new MyCass();
- test(myCass::mymethod);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement