Say you have an interface Aand an interface B. Let's say a class Spriteimplements both interfaces.
A
B
Sprite
Say another class that has a method foo(A object)and also has a method foo(B object).
foo(A object)
foo(B object)
Both are called when I pass the instance to the Spritemethod foo()? If not, does it take precedence?
foo()
When the method is overloaded (as used here), the invocation method is allowed at compile time based on the (declared) type of the variable containing Sprite.
, , , .
. .
interface A {} interface B {} class Sprite implements A,B {} class Test{ void foo(A a){} void foo(B b){} void test(){ Sprite s = new Sprite(); foo(s); // <-- compile time error (The method foo(A) is ambiguous for the type Test) } }
; . .
, , . , .
, , , , , . A , B, A B. , A () B. , , , - " " , " " . . .
Source: https://habr.com/ru/post/1793853/More articles:C ++ Array of function pointers: assign function using char - c ++How can I encode an effective mobile site like gmail? - mobile-websiteReading an empty line C ++ - c ++Как я могу читать данные из элементов управления в окне в другом приложении? - c#Is Parsing C header file possible using ANTLR? - cParsing C Header Files in C # - c #Prolog as DSL for generating Perl code? - perlIs it possible to have an array of unknown types? - genericsMemory leak tracing using AppVerifier - c ++Aligning runtime views in RelativeLayout - androidAll Articles