2

I am posting a code snippet that does not give any syntax error when an interface extends and abstract class. The interface audio extends abstract class music in the method sort()

import java.util.List;
abstract class music {}
public interface audio {}

abstract class play implements Comparable <play> {

    public <audio extends music> void sort (List <music> list){
        //do something 
    }

}

I am assuming an interface CAN NOT extend an abstract class. Can any one explain why it is so?

2 Answers 2

5

In your example, the second "audio" is not the interface, but a type parameter to your generic method. You could just as well name it T.

Sign up to request clarification or add additional context in comments.

Comments

2

You misunderstand. Your type parameter audio is hiding the interface audio.

public <T extends music> void sort(List<music> list) {
    // do something
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.