小编use*_*286的帖子

用不同的签名java实现

当我开发一个满足我需求的类架构时,我遇到了这种情况.我有一个抽象类,其中包含一些必须由子类实现的方法,但在子类中,我发现我需要实现从第一个继承的签名.

告诉你我的意思:

// person class
public abstract class Person
{ 
  protected void abstract workWith(Object o) throws Exception;
}

//developer class
public class Developer extends Person
{// i want to implement this method with Computer parametre instead of Object and throws `//DeveloperException instead of Exception`
 protected void workWith(Computer o) throws DeveloperException
 {
  //some code here lol install linux ide server and stuff 
 }
}

// exception class 
public class DeveloperException extends Exception
{

}
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?我不知道是否可以使用泛型.非常感谢.

java generics

4
推荐指数
1
解决办法
95
查看次数

标签 统计

generics ×1

java ×1