Why is this Java method call considered ambiguous?

前端 未结 2 1566
野性不改
野性不改 2021-01-01 19:30

I\'ve come across a strange error message that I believe may be incorrect. Consider the following code:

public class         


        
2条回答
  •  情书的邮戳
    2021-01-01 20:06

    Your question is very similar to this one.

    The short answer is:

    Overloaded::genuinelyAmbiguous;
    Overloaded::notAmbiguous;
    Overloaded::strangelyAmbiguous;
    

    all these method references are inexact (they have multiple overloads). Consequently, according to the JLS §15.12.2.2., they are skipped from the applicability check during overload resolution, which results in ambiguity.

    In this case, you need to specify the type explicitly, for example:

    load((Processor) Overloaded::genuinelyAmbiguous);
    load(( Supplier) Overloaded::strangelyAmbiguous);
    

提交回复
热议问题