Question: ```
package apc.dastruc.algorithms;

public class BinarySearch<K>{

    public void bubbleSorting(K[] haystack){
        int j = 0;
        int i = 0;
        int temp;

            while(j < (haystack.length - j)){
                    while (i < (haystack.length - 1)){
                        if(haystack[i] > haystack[i + 1]){
                            temp = haystack[i];
                            haystack[i] = haystack[i - 1];
                            haystack[i - 1] = temp;
                        }
                    }
            }

    }

    public int search(K[] haystack, K needle){
        bubbleSorting(haystack);

        int i = haystack.length / 2;

        while(i > 0 && i > haystack.length){
            if(needle.equals(haystack[i])){
                return i;
            }else if(needle < haystack[i]){
                i--;
            }else if(needle > haystack[i]){
                i++;
            }
        } 

        return -1; //no match is found
    }

}

```

The thing is that we are required to make them generics. So i can't really just change their types to int.

Answer: 
If K implements Comparable, then you can do it like this:

```
        if(needle.compareTo(haystack[i]) == 0){
            return i;
        } else if(needle.compareTo(haystack[i]) > 0){
            i--;
        } else {
            i++;
        }

```

Your code will also want to enforce that K implements Comparable in order to do this, i.e:

```
public class BinarySearch<K extends Comparable<K>>

```

I think you might want to look into the Comparable interface.
In this line you are trying to compare two objects of type `K` using the `>` operator:

```
if(haystack[i] > haystack[i + 1]){

```

That does not work, because you cannot compare arbitrary objects with `>`.

One way to solve this is to put a constraint on the type `K`, specifying that it must be a type that implements `Comparable<K>`, and then use the methods of `Comparable` to compare the objects:

```
public class BinarySearch<K extends Comparable<K>> {

    public void bubbleSorting(K[] haystack){
        // ...
        if (haystack[i].compareTo(haystack[i + 1]) > 0) {
            // ...
        }
    }
}

```