Optimising Help
Suppose I define a class
class test1
{
Stack myvar = new Stack();
class test1()
{
}
public boolean idosomethinghere()
{
return myvar.empty();
}
}
now I have reason to use the class again so I create a new instance of the class test1.
Another way would be to redefine the class to below.
class test1
{
class test1()
{
}
public boolean idosomethinghere(Stack myvar)
{
return myvar.empty();
}
}
this way I only ever need one instance which is probably better but have to re-create a new stack anyway. but I am in the situation that it is easier for me to do this the first way. I want to understand how the compiler and the java virtual machine work. By creating a new Instance does the jvm simple recreate the dynamic information like in this case it would be a new stack (the objects fields) and it would simple only create the methods of the class once. Or does it re-create the hole class in memory lock stock and two smoking barrells. Cause with big class that would chew up memory. but you can understand that it would be so much easier to do it that way. programming wise

