[英]Interface overloading
I have created an interface Response
我已经创建了一个
interface Response
Interface Response{
public output(String s);
}
and i implement this interface on my class A
. 我在
class A
上实现了此接口。 now i have a class B
too and it also need to implement this interface but it need different parameter for interface method. 现在我也有一个
class B
,它也需要实现此接口,但它需要不同的参数作为接口方法。 (mean class B needs public output(Comment c);
) (平均B级需要
public output(Comment c);
)
So my question is , do i need to create another interface for class B because it need different parameter 所以我的问题是,我是否需要为类B创建另一个接口,因为它需要不同的参数
Like this 像这样
Interface Response{
public output(Comment c);
}
or is there any way to handle this. 或有什么办法可以解决这个问题。 also can i used
object data type
for this.? 我也可以为此使用
object data type
吗?
Thank you. 谢谢。
Note, this answer applies to Java. 注意,此答案适用于Java。 I am not a C# expert.
我不是C#专家。
I believe you want 我相信你想要
public interface Response<T> {
void output(T arg);
}
Then you can write 那你可以写
public class ClassA implements Response<String> {
public void output(String arg) {
// etc
and also 并且
public class ClassB implements Response<Comment>
public void output(Comment arg) {
// etc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.