sometimes, it need implement two interfaces, like:
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?
分享到:
相关推荐
git-resolve-conflict <strategy> <filename> 使用给定的策略(-我们,-他们的,-联盟)仅解决一个文件中的合并冲突 git resolve-conflict --ours package.jsongit resolve-conflict --theirs package.jsongit ...
(第一次写文章,我经验也不足,根据自己的理解来向大家解释一下) 先说一说今天被折磨一整天的...相信点开这篇文章的同学都已经过了unable to find valid certification这一关,成功为自己的项目配置好了阿里云仓库等
怎样解题(How To Solve It)[美]G.波利亚, 经典名著,不用多说了吧
解决win10操作系统,初始化Eo Webbrowser报错"Failed to resolve LoadLibrary",需要调用eowp.exe,来进行处理,Both EO.Pdf and EO.WebBrowser dynamically create child processes and run browser engine inside ...
版本错误的处理Install Repository and sync project show in file Show in Project Structure dialog
Failed to resolve filter: HomePage console错误信息.jpg 我原来的写法: 原来的错误写法.jpg 错误原因: 经过自己的摸索,后来发现竟然是代码顺序错误问题。 由于先执行的pageList,后执行的Vue的过滤方法,...
没有约定好Collation, 在 MS SQL Server中编程就会遇到这样的问题:Cannot resolve the collation conflict between “Latin1_General_CI_AS” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation. ...
Lenovo X3650 M5 安装 ESXi-5.5.0u3 报错failed to resolve circular relocation-附件资源
主要给大家介绍了关于Android添加glide库报错Error: Failed to resolve: com.android.support:support-annotations:26.0.2的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值...
ERROR: Failed to resolve: com.serenegiant:common:2.12.4 Show in Project Structure dialog 或者 ERROR: Failed to resolve: com.serenegiant:common:1.5.20 Show in Project Structure dialog ``` ...
当用eclipse 导入一个已经存在的项目时,经常会遇见:Unable to resolve target ‘android-XX’ 类似的错误。这是因为导入的项目代码中project.properties 的 Project target 设置与当前eclipse环境设置不一致所致。...
opencv4.1.0使用cmake编译时,提示FFMPEG: Download failed: 6;"Couldn't resolve host name
本篇文章是对android Unable to resolve target 'android-XX'错误的解决方法进行了详细的分析介绍,需要的朋友参考下
前端开源库-resolve-module解析模块,解析模块的最小实现
This paper proposes a novel image mosaic method based on...aiming to resolve incident scaling, rotation, changes in lighting condition, and so on between two images in the panoramic image mosaic process.
Especially, in the case of hard engineering problems, it is possible to adopt a rapidly converging optimization method as a part of the decision-making system, which will receive information in real ...
In this paper, we propose a novel method to generate a revocable minutiae-based fingerprint template. The proposed method consists of feature extraction from fingerprint minutiae pairs, quantization,...