0

I have a class that extends comparable and implements a generic interface and I want to create an instance of that class .

for example

interface MinMax<T extends Comparable<T>> {...}

class Employee<T extends Comparable<T>> implements MinMax<T> {...}

in this example i want to create an instance of Employee , how is that possible ?

1
  • 1
    new Employee<String>() or new Employer<Integer>, for example. You simply need to provide a type variable within the bounds. (Depending on the context, new Employee<>() might work too). Commented Sep 23, 2018 at 18:50

1 Answer 1

2

Employee doesn't need to take a type parameter. You want to make it Comparable and then use it as the type argument for MinMax:

class Employee implements Comparable<Employee>, MinMax<Employee> {
    @Override
    public int compareTo(Employee e) {
        //compare and return...
    }
}

With that, you don't need a type parameter for employee:

Employee e = new Employee(); //or whatever constructor you declared...
Sign up to request clarification or add additional context in comments.

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.