Skip to main content

Test scope variables for changes

3 replies [Last post]
jeremygwa
Offline
Joined: 2006-01-17
Points: 0

What is an affective way of testing variables in a specified scope, to see if variable values have changed?
Can this be done, without explicitly testing each variable, and without having to deal with casts or knowledge of types?
I will be using this for caching purposes.

Thanks in advance for your input.

-Jer A.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linuxhippy
Offline
Joined: 2004-01-07
Points: 0

No as far as I know java does not provide a fast way to get notifications for such changes, it does provide the debugging interface but this is for your purpose way too inefficient.

I would realize the whole system via getters/setter which keep track of changes.

lg Clemens

jeremygwa
Offline
Joined: 2006-01-17
Points: 0

Does java 1.5 support set and get code for field properties, the way that csharp does?, or do I have to form my own?

As far as my problem goes...

I cannot use reflection on fields, as this covers the scope of the entire class.

I suppose I can set up an ArrayList, in which i add variables too in the scope, then compare them with earlier values (by Scope, I mean "Loop"). I could programmatically parse the Loop part of the java source code, adding the ArrayList functionality..then programmatically compile it....does anyone have a better way that does not have too much of an impact on performance?

Is there anyway of just adding references of the object to the ArrayList? In csharp, there is 'ref'(references).Is there a way of reading java memory for java code?

Thanks in advance for all your help and feedback.

-Jer A.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

To be honest I am not quite sure wether I really understood your question or I simply don't get whats the big problem ;)

> Does java 1.5 support set and get code for field
> properties, the way that csharp does?, or do I have
> to form my own?
No you've to form your own (in C# you also have to do, but only once), any good IDE will do that job for you.

> I cannot use reflection on fields, as this covers the
> scope of the entire class.
Well you could give the variables you want to keep track of special names and afterwards only compare variables which which names meete this criteria.
I don't know wether annotations are useful for this, maybe, I've never written java-5 code.

> I suppose I can set up an ArrayList, in which i add
> variables too in the scope, then compare them with
> earlier values (by Scope, I mean "Loop").
For example this could be a way to solve your problem.

> I could
> programmatically parse the Loop part of the java
> source code, adding the ArrayList functionality..then
> programmatically compile it....does anyone have a
> better way that does not have too much of an impact
> on performance?
Performance-whise this is clearly the fastest way but it will be hard to maintain. I would stick with the ArrayList solution.

> Is there anyway of just adding references of the
> object to the ArrayList? In csharp, there is
> 'ref'(references).Is there a way of reading java
> memory for java code?
In java you only add references to arraylists, if I understood your question correctly.
So theres no way to give the ArrayList an object per value, only per reference.

lg Clemens

Just to be curious, where are you from?