Dynamic Method Invocation (specific line)

A

ash

Hello All,


I am using Java Reflection API to dynamically invoke methods from
classes. But i am trying to figure out a way to invoke specific lines
within methods. Is there a way around this problem ?


Thanx in advance for your help
 
L

Lew

ash said:
Hello All,


I am using Java Reflection API to dynamically invoke methods from
classes. But i am trying to figure out a way to invoke specific lines
within methods. Is there a way around this problem ?

No. Why do you call it a "problem"?

More to the point, why are you trying to break the fundamental object-oriented
nature of Java in the first place? It sounds like some other language would
suit your purposes better.

The Java approach would be NOT to use reflection but to design your code. If
you have a few lines of code you want to execute separately, they belong in a
separate method in the first place.

Reflection is no substitute for a good design.
 
P

Patricia Shanahan

Lew said:
No. Why do you call it a "problem"?

More to the point, why are you trying to break the fundamental
object-oriented nature of Java in the first place? It sounds like some
other language would suit your purposes better.

The Java approach would be NOT to use reflection but to design your
code. If you have a few lines of code you want to execute separately,
they belong in a separate method in the first place.

Reflection is no substitute for a good design.

Again, I don't think we will come to a satisfactory answer unless ash
tells us the purpose of these proposed operations.

If Java really is the best language choice for ash's problem, then this
newsgroup's collective knowledge will include good ways of implementing
what ash wants in Java. If Java is not the best language choice, someone
here will be familiar with each language that would be better.

As it is, we are handicapped by not knowing *why* ash wants to do things
that do not really fit with how Java is supposed to be used.

Patricia
 
A

ash

Again, I don't think we will come to a satisfactory answer unless ash
tells us the purpose of these proposed operations.

If Java really is the best language choice for ash's problem, then this
newsgroup's collective knowledge will include good ways of implementing
what ash wants in Java. If Java is not the best language choice, someone
here will be familiar with each language that would be better.

As it is, we are handicapped by not knowing *why* ash wants to do things
that do not really fit with how Java is supposed to be used.


OK , What i am trying to implement here is a visualization software
that would dynamically load a class to the jvm and then execute java
code with at the user desire. the user may want to execute an
algorithm step by step (that means line by line). That's why i am
trying to invoke a method line by line. What i am doing right now is
that i am putting each of the algorithm's statements in a separate
method but i don't like that design and i am trying to change it to
something more cleaner.
 
P

Patricia Shanahan

ash said:
OK , What i am trying to implement here is a visualization software
that would dynamically load a class to the jvm and then execute java
code with at the user desire. the user may want to execute an
algorithm step by step (that means line by line). That's why i am
trying to invoke a method line by line. What i am doing right now is
that i am putting each of the algorithm's statements in a separate
method but i don't like that design and i am trying to change it to
something more cleaner.

Essentially, you are implementing a debugger. Line-by-line execution is
a common debug function. I suggest looking at the debug software
mentioned in the previous thread.

Patricia
 
P

Patricia Shanahan

ash said:
OK , What i am trying to implement here is a visualization software
that would dynamically load a class to the jvm and then execute java
code with at the user desire. the user may want to execute an
algorithm step by step (that means line by line). That's why i am
trying to invoke a method line by line. What i am doing right now is
that i am putting each of the algorithm's statements in a separate
method but i don't like that design and i am trying to change it to
something more cleaner.

Incidentally, the actual requirement, line-by-line execution, is far
more Java-compatible than the attempted solution, invoking an arbitrary
line in a method.

The compile time rules for definite assignment depend on invariants
related to the possible execution ordering of statements within the
method. Line-by-line execution maintains those invariants, so if the
method compiles each uninitialized local variable is the target of an
assignment prior to any use. Execution of an arbitrary statement in the
middle of a method could break the definite assignment invariants,
leading to the use of a local variable that does not have a defined value.

Patricia
 
R

Roedy Green

I am using Java Reflection API to dynamically invoke methods from
classes. But i am trying to figure out a way to invoke specific lines
within methods. Is there a way around this problem ?

you would have to do something like pass a parm given to a switch to
select the single line you wanted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top