英文:
Cannot clear java class from memory
问题
我有一个简单的Java类,如下所示:
public class Add2Numbers
{
public static void main(String[] args)
{
int num1=2, num2=4, sum;
sum = num1 + num2;
System.out.println("这两个数字的和:" + sum);
}
}
我编译这个类,并在MATLAB中运行,使用以下代码:
obj = Add2Numbers;
javaMethod('main', obj,"");
我得到的输出是:**这两个数字的和: 6**,这当然是正确的。
接下来,我在文本编辑器中更改了代码(例如设置**num1=4**),编译,执行如下清除语句:
clear all
clear java
clear import
clear CLASSES
clear ALL
clear
然后再次运行:
obj = Add2Numbers;
javaMethod('main', obj,"");
但是计算结果与之前保持相同。如果我关闭并重新启动MATLAB,则修改后的Java类将正确运行。那么在不必关闭MATLAB并重新启动的情况下,我如何清除Java类呢?
英文:
I have a simple java class as shown below:
public class Add2Numbers
{
public static void main(String[] args)
{
int num1=2, num2=4, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
}
I compile the class and run in matlab using:
obj = Add2Numbers;
javaMethod('main', o,"");
and I get the output: Sum of these numbers: 6 which is, of course, correct.
Next I change the code in my text editor (e.g. set num1=4) compile, execute the clear statements below:
clear all
clear java
clear import
clear CLASSES
clear ALL
clear
then run again:
obj = Add2Numbers;
javaMethod('main', o,"");
But the calculation result remains the same as before. If I close and restart MATLAB the modified java class runs correctly. So how on earth do I clear a java class without having to close MATLAB and restart it?
set
专注分享java语言的经验与见解,让所有开发者获益!
评论