java - Interface methods - implementation vs. definition -
please explain why following isn't valid in java (1.7).
having interface:
interface foo { mymethod(argument arg) }
where argument
interface:
interface argument{}
an implementation of argument
:
class someargument implements argument{}
and implementation of foo
:
class bar implements foo { mymethod(someargument arg) {} }
the class bar
results in compilation errors, since mymethod
isn't implemented. there anyway accomplish above out need of casting?
thanks!
the mymethod()
signature has exact defined in foo
interface.
suppose have class (baz
) implements argument
. then, mymethod(argument arg)
signature allow passing parameters of baz
type.
but if keep this:
class bar implements foo { mymethod(someargument arg) {} }
you not able pass baz
instances mymethod
, because you've broken contract.
as side note, should follow naming conventions when developing!
Comments
Post a Comment