0

I want make my List. But I dont know how to write generic type in java.


public interface myListInt <E extends Comparable<E>>{}

public class myList<E extends myListInt<E>> extends LinkedList{}

When I am doing that, it gives an error.How should ı write.

Jamil
  • 5,457
  • 4
  • 26
  • 29
o_O
  • 51
  • 7

1 Answers1

0

The exact intent of your code is unclear, but I got an error for the <E> in myListInt<E>.

public interface myListInt <E extends Comparable<E>>{}
public class myList<E extends myListInt<E>> extends LinkedList{}
                                        ^ Error here

This is because you need to constrain E to extend Comparable<E> in order to be a valid bound for myListInt<E>:

public class myList<E extends Comparable<E> & myListInt<E>>
    extends LinkedList{}

However, you maybe also want to add a constraint to LinkedList too (assuming this is java.util.LinkedList:

public class myList<E extends Comparable<E> & myListInt<E>>
    extends LinkedList<E> {}
Andy Turner
  • 137,514
  • 11
  • 162
  • 243