Hi,
I'm developing a mathemathical model which needs to apply a certain method to many different functions.
To acomplish this I'm using an Interface, which I have read is the most common procedure to pass a functions as a parameters.
/**
* Define a common interface to be able to calculate the Residues of different functions
*/
public interface ComplexFunction {
Complex value(Complex k, double m);
}
/**
* Define the function
*/
private class A2Complex implements ComplexFunction {
public Complex value(Complex k, double m) {
.....
}
/**
* Pass the function
*/
private double A20(double k0, double m) {
ComplexFunction A2C = new A2Complex();
return Residue(new ResidueFunction(A2C, k0, m));
}
So far, so good.
But the problem arises when I try to use this code:
System.out.println(String.valueOf( A20(5.0,1.0) );
The compiler tells me to declare A20 as static, but when I do so, I get an error in the "new A2Complex();" line saying "No enclosing instance is accesible"
I'm clearly not understanding properly the implications of making a method Static.
Could somebody please help me understanding this?
Thanks in advance,
JBB
I'm developing a mathemathical model which needs to apply a certain method to many different functions.
To acomplish this I'm using an Interface, which I have read is the most common procedure to pass a functions as a parameters.
/**
* Define a common interface to be able to calculate the Residues of different functions
*/
public interface ComplexFunction {
Complex value(Complex k, double m);
}
/**
* Define the function
*/
private class A2Complex implements ComplexFunction {
public Complex value(Complex k, double m) {
.....
}
/**
* Pass the function
*/
private double A20(double k0, double m) {
ComplexFunction A2C = new A2Complex();
return Residue(new ResidueFunction(A2C, k0, m));
}
So far, so good.
But the problem arises when I try to use this code:
System.out.println(String.valueOf( A20(5.0,1.0) );
The compiler tells me to declare A20 as static, but when I do so, I get an error in the "new A2Complex();" line saying "No enclosing instance is accesible"
I'm clearly not understanding properly the implications of making a method Static.
Could somebody please help me understanding this?
Thanks in advance,
JBB