Instantiating a class does not work, constructor parameter is interface

103 views Asked by At

i tried to create a instance of a class that implemented an interface, but the problem is that the constructor takes a parameter which is the interface itself.

Information: I dont want to implement the interface, class or funcinality by myself, because the library EJML has implemented it already, i just want to use the class and the functions.

    public class myMatrixFactory{
        public void do(){
            //Does not work because LinearSolver_B64_to_D64() needs a interface as parameter
            // parameter is LinearSolver<BlockMatrix64F> which is an interface
            LinearSolver_B64_to_D64 ls = new LinearSolver_B64_to_D64(????);
        }
    }
1

There are 1 answers

2
JayTheKay On BEST ANSWER

You have to create an object of a class that implements the required interface and pass it to the constructor.

According to the link you provided you need an object of type LinearSolver<BlockMatrix64F> so you should take a look at this classes javadoc and choose one of the implementing classes.