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.
I suggest you try
(You need both
Speak.jarandmyPerson.jaron the classpath to instantiate amyPerson.)