Hard to resolve method signature conflict in two interfaces
来源:互联网 发布:黑帽seo基础知识 编辑:程序博客网 时间:2024/05/17 01:16
sometimes, it need implement two interfaces, like:
usually, it can be done like:
then Java compile will complain on can't different those two methods which you must implement in your concrete class, so here have two choices:
1. if those two interfaces are own by you, then you can change the signature of those methods
2. otherwise, you can write a abstract class first like:
then let your concrete class extends your abstract class and implements IBface again like:
this fix the name conflict, but lost interface value because when do like:
it may even worse when you haven't the right to change source code of IAface and IBface, so seems pay attention to naming in programming is so important, but sometimes it can't guarantee all names won't conflict especially when you want to extend/implement others' code
what's your insight?
public interface IAface { public static final String A = "AFACE"; public int doSmile();}public interface IBface { public static final String B = "BFACE"; public String doSmile();}
usually, it can be done like:
public class Face implements IAface, IBface { public int doSmile() { ... } public String doSmile() { ... }}
then Java compile will complain on can't different those two methods which you must implement in your concrete class, so here have two choices:
1. if those two interfaces are own by you, then you can change the signature of those methods
2. otherwise, you can write a abstract class first like:
public abstract class MyAface implements IAface { public int doSmile() { return -1; } public abstract int myDoSmile();}
then let your concrete class extends your abstract class and implements IBface again like:
public class Face2 extends MyAface implements IBface { public int myDoSmile() { ... } public String doSmile() { ... }}
this fix the name conflict, but lost interface value because when do like:
IAface aface = new Face2(); aface.doSmile(); //ok aface.myDoSmile(); //can't do like this
it may even worse when you haven't the right to change source code of IAface and IBface, so seems pay attention to naming in programming is so important, but sometimes it can't guarantee all names won't conflict especially when you want to extend/implement others' code
what's your insight?
- Hard to resolve method signature conflict in two interfaces
- SVN: How to resolve a conflict tutorial
- sql左连接时发生字符集错误Cannot resolve the collation conflict between in the equal to operation.
- Error:"No method with signature" in OAF
- "Cannot resolve collation conflict for column 1 in SELECT statement."
- Cannot resolve collation conflict for equal to operation.
- Cannot resolve collation conflict for equal to operation
- Cannot resolve collation conflict for equal to operation.
- Property “Value” is already defined. Use to resolve this conflict.
- How to use interfaces in Go
- android unable to resolve static method ****: 解决方法
- unable to resolve virtual method 错误
- Resolve Tree Conflict SVN
- cannot resolve method,validates method refences in code configuration
- How to setup signature image in outlook
- 解决 Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this
- Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly
- Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly
- 巧用 ROW_NUMBER() 生成不重复的唯一排序码,按客户的需要任意排序数据
- [数据预处理]分箱:数值字段转为集合字段
- Load any resource from any installed plugin of Eclipse
- 好人和老好人的区别
- java做的iphone推送,水平有限,单个推送还可以,上万的推送写的线程不知道怎么样,高人可一指点下。
- Hard to resolve method signature conflict in two interfaces
- Java remote debug in jdk 5.0
- Joel test : how much does your company get?
- Profile your Eclipse plugins using TPTP
- A simple demo yet reveal core concept of OSGi
- Good introduction on OSGi
- 视频通讯与在线客服
- Gang of Four
- Eclipse lazy loading flag changed from time to time