S
Shawn
Hi,
I am doing some scientific programming using Java. I have a static
method doing some calculation. To help its calculation, I hope to have a
class Helper inside the method doing some routine, modular calculation.
But I ran into 2 problems. Could you help me out? Thank you very much.
==============Subroutines.java===========
class MyClass
{
public double A, B;
}
public class Subroutines
{
public static double getValue(MyClass obj) //Question 1: I need "final
MyClass obi", why? Because inside the method, obj needs to be
modified/updated, adding final will prevent it be changed or not?
{
class Helper //Question 2: I hope it can be static, so I can
Helper.getDiff(), instead of new Helper().getDiff(). But my compiler
won't let me do it.
{
public static double getDiff()
{
retunr (obj.A-obj.B);
}
}
//start doing calculation
Helper helper = new Helper();
...//code for doing calculation. I simplified here in the posting
return helper.getDiff();
}
}
I am doing some scientific programming using Java. I have a static
method doing some calculation. To help its calculation, I hope to have a
class Helper inside the method doing some routine, modular calculation.
But I ran into 2 problems. Could you help me out? Thank you very much.
==============Subroutines.java===========
class MyClass
{
public double A, B;
}
public class Subroutines
{
public static double getValue(MyClass obj) //Question 1: I need "final
MyClass obi", why? Because inside the method, obj needs to be
modified/updated, adding final will prevent it be changed or not?
{
class Helper //Question 2: I hope it can be static, so I can
Helper.getDiff(), instead of new Helper().getDiff(). But my compiler
won't let me do it.
{
public static double getDiff()
{
retunr (obj.A-obj.B);
}
}
//start doing calculation
Helper helper = new Helper();
...//code for doing calculation. I simplified here in the posting
return helper.getDiff();
}
}