Roronoa Zoro
Roronoa Zoro

Reputation: 1013

Create Java object that implements an interface from Matlab

For some reason, I am not able to create a Java object that implements a user-defined interface.

I tried creating a Java object that implements a pre-defined interface and it worked fine.

My interface:

public interface Speak 
{
    public void sayHello();
}

My Class:

public class myPerson 
implements Speak
{
    public myPerson(String arg_firstName, int arg_age)
    {
        firstName = arg_firstName;
        age = arg_age;
    }

    public String firstName;
    public int age;

    @Override
    public void sayHello() {
        // TODO Auto-generated method stub
    }
}

For my class to work in eclipse, I had to export my interface as a .jar file, then I added it to the project libraries - and it worked just fine.

My Matlab file:

clc
clear

javaclasspath('/path/to/Speak.jar');
javaclasspath('/path/to/myPerson.jar');

driver_1 = myPerson('Bob', 39);

The error that I'm getting is:

Undefined function or variable 'myPerson'.

If I remove the implements interface, I can create the object just fine.

Upvotes: 1

Views: 456

Answers (1)

aioobe
aioobe

Reputation: 421310

I suggest you try

javaclasspath({'/path/to/Speak.jar', '/path/to/myPerson.jar'});

(You need both Speak.jar and myPerson.jar on the classpath to instantiate a myPerson.)

Upvotes: 1

Related Questions