0

Right now, I am trying to create an instance of a generic class BTree<T> which implements an interface SSet<T> which in turn implements Iterable<T> I've deleted the bulk of the code out of the BTree<T> class and left only the constructor. Though, if it's essential, I can add the entire code if anyone believes it is helpful. The BTree<T> class looks something like this:

package assignment2_draft;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

public class BTree<T> implements SSet<T> {

    //Some methods

    public BTree(int b, Class<T> clz) {
    this(b, new DefaultComparator<T>(), clz);
    }

}

In my own class, I am trying to call the BTree<T> class and pass an Integer into the generic. In my class, I have:

BTree<Integer> myTree=new BTree<Integer>(Integer.class);

which has worked in generic classes before, but not this class. I am wondering, am I passing in the parameters right? Or do I need to somehow reference SSet<T> when creating an instance of BTree<T>

Damien Scott
  • 47
  • 1
  • 4
  • Implements an ***abstract*** interface? As opposed to what other kind of interface? [JLS §9.1.1.1](https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.1.1.1): ***Every** interface is implicitly `abstract`.* – Andreas Nov 03 '17 at 05:53

2 Answers2

3

Your constructor signature is BTree(int, Class<T>)

So it would seem you need to do something like

SSet<Integer> tree = new BTree<Integer>(2, Integer.class);

Notice the reference is an SSet<> not a BTree<> - you COULD use a BTree<> reference there, if you wanted, but in general it's preferable to program to an interface unless you have a reason not to.

corsiKa
  • 81,495
  • 25
  • 153
  • 204
0

Your Constructor which you provided above, accept two value

public BTree(int b, Class<T> clz) {
this(b, new DefaultComparator<T>(), clz);
}

but you are providing only one,

BTree<Integer> myTree=new BTree<Integer>(Integer.class);

does do you have any other constructor ,If not then use following

int a=5; 
SSet<Integer> myTree=new BTree<Integer>(a,Integer.class);
Manish Jaiswal
  • 442
  • 5
  • 19