Skip to content
Advertisement

incompatible types: int cannot be converted to T

I’m getting this error, here is the necessary code. Assume the methods not here work correctly. Any help would be awesome. (I am coding on a text file in Ubuntu btw)

Here is the error message: (after compiling)

BinarySearchTree.java:132: error: incompatible types: int cannot be converted to T insert(y); ^ where T is a type-variable: T extends Comparable<? super T> declared in class BinarySearchTree Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

Verbose error message:

BinarySearchTree.java:132: error: no suitable method found for insert(int) insert(y); ^ method BinarySearchTree.insert(T) is not applicable (argument mismatch; int cannot be converted to T) method BinarySearchTree.insert(T,BinaryNode) is not applicable (actual and formal argument lists differ in length) where T is a type-variable: T extends Comparable<? super T> declared in class BinarySearchTree 1 error

Here is my code:

JavaScript

Advertisement

Answer

You have a generic parameter so it will be logically correct for you to create a new tree when reading CSV.

This also means insertList(...) should become static and now be invoked like BinarySearchTree<Integer> tree = BinarySearchTree.insertList(...)

Here is the code:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement