如何将接口名称映射到不同的方法名称? [英] How to map interface names to different method names?

查看:155
本文介绍了如何将接口名称映射到不同的方法名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个实现接口的对象,它会默认将接口方法自动映射到具有相同名称和签名的类的方法上。有没有办法覆盖它并将接口方法映射到具有相同签名但名称不同的方法? (这可能很有用,例如,如果我实现了两个接口,这两个接口都有一个具有相同名称和签名的方法,我希望能够用它们做不同的事情。)

If I have an object that implements an interface, it maps the interface methods automatically onto the class's methods with the same name and signature by default. Is there any way to override this and map an interface method onto a method with the same signature but a different name? (This could be useful, for example, if I implement two interfaces, both of which have a method with the same name and signature, and I want to be able to do different things with them.)

推荐答案

这确实是可能的。该技术称为方法解决条款

It is indeed possible. The technique is called Method Resolution Clause.

这篇关于如何将接口名称映射到不同的方法名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆