fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9.  
  10. private PriorityQueue<Node<Integer>> maxPriorityQueue;
  11.  
  12. // this will fail to compile because fo bounds (non implementing Compatable)
  13. //private PriorityQueue<NonComparable> ncPriorityQueue;
  14.  
  15. public static void main (String[] args) throws java.lang.Exception {
  16.  
  17. }
  18.  
  19. public Ideone() {
  20. maxPriorityQueue = new PriorityQueue<>();
  21. Node<String> sNode = new Node<>("test");
  22. Node<Integer> iNode = new Node<>(7);
  23. maxPriorityQueue.add(iNode);
  24. //this will fail to compile because of node type parameter
  25. //maxPriorityQueue.add(sNode);
  26. }
  27. }
  28.  
  29.  
  30. class NonComparable {}
  31.  
  32. class Node<T> implements Comparable<Node<T>> {
  33.  
  34. private T info;
  35. private Node next;
  36. private Node previous;
  37.  
  38. public Node(T payload) {
  39. info = payload;
  40. }
  41.  
  42. public int compareTo(Node<T> other) {
  43. return 0;
  44. }
  45. }
  46.  
  47. class PriorityQueue<Item extends Comparable<Item>> implements Iterable<Item> {
  48.  
  49. private List<Item> list = new ArrayList<>();
  50.  
  51. public Iterator<Item> iterator() {
  52. return null;
  53. }
  54.  
  55. public void add(Item item) {
  56. list.add(item);
  57. }
  58.  
  59. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
Standard output is empty