In Java, how does one create a custom ceiling method with generic types?

Viewed 33

The class that this method is in extends Comparable, however, I am having an issue comparing generic values. Here is what I have tried:

Node class:

private class Node {
        private Key key;
        private Value value;
        private Node next;
        private Node(Key key, Value val) {
            this.key = key;
            this.value = val;
            this.next = null;
        }
// Getters and setters emitted in this snippet.

Class containing ceiling method:

public class STable<Key extends Comparable<Key>, <Value> implements Iterable<Key> {
    public Key ceiling (Key key) {
        Node temp = this.head;
        Key ceiling = null;

        for (Key k: this) {
            int cmp = k.compareTo(key);
            if(cmp < 0){
                ceiling = temp.getKey();
            } else {
                ceiling = k;
                return ceiling;
            }
        }
        return ceiling;
    }
    
}
0 Answers
Related