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?
分享到:
相关推荐
在Android开发过程中,经常会遇到"Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:29.+”这样的错误提示,这是由于依赖库无法正确解析导致的。该错误通常涉及到Android支持库版本不匹配或者...
(第一次写文章,我经验也不足,根据自己的理解来向大家解释一下) 先说一说今天被折磨一整天的...相信点开这篇文章的同学都已经过了unable to find valid certification这一关,成功为自己的项目配置好了阿里云仓库等
git-resolve-conflict <strategy> <filename> 使用给定的策略(-我们,-他们的,-联盟)仅解决一个文件中的合并冲突 git resolve-conflict --ours package.jsongit resolve-conflict --theirs package.jsongit ...
### 如何解决问题——基于G.波利亚的《怎样解题》 #### 一、引言 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 ...
Failed to resolve filter: HomePage console错误信息.jpg 我原来的写法: 原来的错误写法.jpg 错误原因: 经过自己的摸索,后来发现竟然是代码顺序错误问题。 由于先执行的pageList,后执行的Vue的过滤方法,...
Failed to resolve module(解决方案).md
Lenovo X3650 M5 安装 ESXi-5.5.0u3 报错failed to resolve circular relocation-附件资源
当遇到"Failed to resolve"错误时,可能是由于以下原因: 1. `build.gradle`文件中未正确配置`support-annotations`依赖。解决方法是在`dependencies`块中添加如下代码: ```gradle dependencies { ...
主要解决android找不到ContextCompat.checkSelfPermission的问题,但导入最新的android-support-v4.jar后,又报出appcompat_v7的版本不符之类的问题。
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 ``` ...
在Android开发过程中,开发者可能遇到一个常见的问题,即“Unable to resolve target ‘android-XX’”。这个错误通常出现在使用Eclipse导入已有的Android项目时,表明项目中的`project.properties`文件中设定的目标...
Couldn't resolve host name"”。这个错误意味着在下载或更新FFmpeg库的过程中,系统无法解析主机名,可能是网络问题、DNS配置错误或是CMake脚本中的URL问题。 首先,我们来理解这个问题的根源。在OpenCV的...
"resolve-module" 是一个专门用于解析模块的开源库,它实现了模块解析的最基本功能,适用于构建工具、打包器等场景。这个库的核心目标是帮助前端开发者解决在项目中引用模块时遇到的路径查找问题。 在JavaScript...
在Android开发过程中,开发者可能会遇到“Unable to resolve target 'android-XX'”的错误提示,这通常是由于项目配置与开发环境之间存在不匹配导致的。本文将深入解析这个错误,并提供详细的解决步骤。 首先,我们...
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 ``` 报...