0

I need that Inteface is implemented by different classes for its methods but also in order to use polymorphism on that supertype. All the classes have the same characteristics and they must be children of a superclass or implement the same interface.

However one of the classes that implement Interface needs its methods but it should not be of type Interface.

Is there a way to exclude a class from polymorphism without cloning Interface and use it just for one class?


This is somewhere the interface I need it implements:

@FunctionalInterface
public interface Interface
{
    Rapport makeRapport(Collection<Student> studs);

    default RapportType getType() 
    {
        return this.getClass().getAnnotation(Type.class).value();
    }    

}
Luca
  • 51
  • 3
  • Not sure what you mean by exlcuding from polymorphism. Can you include any code? – Tim Biegeleisen May 19 '18 at 09:29
  • "_However one of the classes that implement `Interface` needs its methods but it should not be of type `Interface`._" This makes no sense - if it `implements` the `interface` then it _by definition_ _is a_; this is what inheritance means. Presumably you need the methods in order to call them - this makes it an `Interface`. – Boris the Spider May 19 '18 at 09:30
  • 1
    What do you mean "needs its methods"? Can't it just implement those methods without implementing Interface? – Marco May 19 '18 at 09:48
  • Interface has a default method and one abstract method. My subclasses need to be a Interface, also (but not only) because they use those methods. One class of them is a bit different and it causes problems other classes don't cause, so I would like to implement that interface without considering that class an Interface. – Luca May 19 '18 at 09:59
  • [**PREFER COMPOSITION OVER INHERITANCE**](https://stackoverflow.com/questions/49002/prefer-composition-over-inheritance). This is why. So you don't end up with this. Whatever "this" is. – Boris the Spider May 19 '18 at 10:02

0 Answers0