无法从内存中清除Java类

huangapple 未分类评论54阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年6月6日 00:05:11
  • 转载请务必保留本文链接:https://java.coder-hub.com/62219593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定