-2
public interface A {
  public void setStar(Star star)
}

public class A-Class implements A {
 public void setStar(StarImpl star)
}

public interface Star {
}

public class StarImpl implements Star {
}

So basically, I want to apply interface A to A-Class. But it gives me error: A-Class is not abstract and does not override abstract method setStar(Star).

I know the reason is that setStar() in A-class is not exact as the one in interface A. But I don't know how to use generic to fix it? Any ideas? Thanks you very much!

What I tried:

public class A-Class implements A {
 public void setStar(<? extends Star> star)
}

public class A-Class implements A {
 public <T extends Star> void setStar(T star)
}

Both of them doesn't work. Again, thanks in advance!

Haoyu Chen
  • 1,760
  • 1
  • 22
  • 32

1 Answers1

0
public interface A<T extends Star> {
  public void setStar(T star)
}

After some trying, I solved the problem by myself. Basically, it's to add generic to interface A. Thanks, guys!

Haoyu Chen
  • 1,760
  • 1
  • 22
  • 32