Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dynamic Method Invocation (specific line)

Reply
Thread Tools

Dynamic Method Invocation (specific line)

 
 
ash
Guest
Posts: n/a
 
      03-18-2008
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
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      03-18-2008
ash wrote:
> 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.

--
Lew
 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      03-18-2008
Lew wrote:
> ash wrote:
>> 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.
>


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
 
Reply With Quote
 
ash
Guest
Posts: n/a
 
      03-18-2008
>
> 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.

 
Reply With Quote
 
Patricia Shanahan
Guest
Posts: n/a
 
      03-18-2008
ash wrote:
>> 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.
>


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
 
Reply With Quote
 
ash
Guest
Posts: n/a
 
      03-18-2008
Yup , JDI solved the problem
 
Reply With Quote
 
Patricia Shanahan
Guest
Posts: n/a
 
      03-19-2008
ash wrote:
>> 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.
>


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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-19-2008
On Mon, 17 Mar 2008 23:10:22 -0700 (PDT), ash <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

> 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.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-19-2008
On Tue, 18 Mar 2008 09:08:37 -0700 (PDT), ash <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>the user may want to execute an
>algorithm step by step (that means line by line).


You want to have a look at the debugging interface.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic method invocation on Proxy object? Sebastian Java 2 02-08-2012 02:16 PM
Dynamic method invocation jythonuser Python 3 06-26-2009 10:16 PM
cleaning up some reflection / dynamic method invocation code Marc E Java 2 07-19-2006 02:00 AM
Dynamic invocation of web services? Generic Usenet Account XML 1 06-23-2004 03:11 AM
dynamic type invocation in applets across jars Jonathan Shore Java 1 10-12-2003 07:45 PM



Advertisments