Dynamic Method Invocation (specific line)

Discussion in 'Java' started by ash, Mar 18, 2008.

  1. ash

    ash Guest

    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
    ash, Mar 18, 2008
    #1
    1. Advertising

  2. ash

    Lew Guest

    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
    Lew, Mar 18, 2008
    #2
    1. Advertising

  3. 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
    Patricia Shanahan, Mar 18, 2008
    #3
  4. ash

    ash Guest

    >
    > 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.
    ash, Mar 18, 2008
    #4
  5. 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
    Patricia Shanahan, Mar 18, 2008
    #5
  6. ash

    ash Guest

    Yup , JDI solved the problem
    ash, Mar 18, 2008
    #6
  7. 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
    Patricia Shanahan, Mar 19, 2008
    #7
  8. ash

    Roedy Green Guest

    On Mon, 17 Mar 2008 23:10:22 -0700 (PDT), ash <>
    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
    Roedy Green, Mar 19, 2008
    #8
  9. ash

    Roedy Green Guest

    On Tue, 18 Mar 2008 09:08:37 -0700 (PDT), ash <>
    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
    Roedy Green, Mar 19, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Shore
    Replies:
    1
    Views:
    351
  2. Ike
    Replies:
    2
    Views:
    456
    Roedy Green
    Jul 8, 2004
  3. Marc E
    Replies:
    2
    Views:
    500
    Marc E
    Jul 19, 2006
  4. jythonuser

    Dynamic method invocation

    jythonuser, Jun 23, 2009, in forum: Python
    Replies:
    3
    Views:
    690
    jythonuser
    Jun 26, 2009
  5. Sebastian
    Replies:
    2
    Views:
    470
    Sebastian
    Feb 8, 2012
Loading...

Share This Page