4

How to specify lambda expression in JAVA when I have two same name method?

JAVA8

package com.gsy;  

import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStream;  
import java.io.InputStreamReader;  
import java.net.URL;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.Comparator;  
import java.util.Date;  
import java.util.ResourceBundle;  

public class EmailProperty {  
    public static void main(String args[]) {  


    }  
    interface qqq{  
        int a(int a);  
    }  
    interface ppp{  
        int a(int b);  
    }  
    class test{  
        int a;  
        int b;  
        int testa(int a,int b,qqq qqq){  
            return 1;  
        }  
        int testa(int a,int b,ppp ppp){  
            return 1;  
        }  
    }  
    public EmailProperty() {  
        test aaa = new test();  
        aaa.a = 1;  
        aaa.b = 2;  

        aaa.testa(1, 2,new ppp() {  

            @Override  
            public int a(int b) {  
                // TODO Auto-generated method stub  
                return 0;  
            }  
        });  
        aaa.testa(1, 2,???);  
    }  
}  

what I can write in ???,and don`t need to use Anonymous function.I cant find any method to specify ppp or qqq when I use lambda.

1 Answer 1

5

You can cast:

aaa.testa(1, 2, (qqq) i -> 0); 
aaa.testa(1, 2, (ppp) i -> 0);  

Or use a variable:

qqq q = i -> 0;
aaa.testa(1, 2, q);
Sign up to request clarification or add additional context in comments.

1 Comment

Thks!IThis is really helpful to me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.