G
gajo
I was wondering if it's possible to use anonymous inner blocks the same way
you use anonymous classes. Like in the following case:
int i = {
int a = 5;
return a*2;
};
System.out.println(i);
I know this won't work, but you get the idea. This is only a simple example,
but I actually did come to this while writing a huge chunk of code which had
only the purpose of initializing an object. Many variables were used that
would only be used once, and then later the program would never use them
again, but they would stay resident in the memory because they belong to the
same block.
Now, if I was able to do what I wrote in that example above, I could use
tons of variables in one inner block, and in the end throw them all away and
return only the finished "product"
Oh, and don't tell me that I should put that block in a method of a class,
and call that method. I did do that in the end, but I had to add a lot of
extra inner-connections between the classes, and the program lost its
flexibility. If I was able to do the above mentioned code, I would have
solved the problem in minutes, not hours.
Gajo
you use anonymous classes. Like in the following case:
int i = {
int a = 5;
return a*2;
};
System.out.println(i);
I know this won't work, but you get the idea. This is only a simple example,
but I actually did come to this while writing a huge chunk of code which had
only the purpose of initializing an object. Many variables were used that
would only be used once, and then later the program would never use them
again, but they would stay resident in the memory because they belong to the
same block.
Now, if I was able to do what I wrote in that example above, I could use
tons of variables in one inner block, and in the end throw them all away and
return only the finished "product"
Oh, and don't tell me that I should put that block in a method of a class,
and call that method. I did do that in the end, but I had to add a lot of
extra inner-connections between the classes, and the program lost its
flexibility. If I was able to do the above mentioned code, I would have
solved the problem in minutes, not hours.
Gajo