Method inside method problem, please advise

Discussion in 'Java' started by tobleron, Nov 25, 2008.

  1. tobleron

    tobleron Guest

    Hi,

    I have 2 files.

    File A.java

    public class A {
    @Action public void bla1(){
    blaaa1111....
    }
    @Action public void bla2(){
    blaaa2222....
    }
    }

    File B.java

    public class B {
    public static void ble1(){
    bleee1111....
    }
    public static void ble2(){
    bleee2222....
    }
    public static void ble3(){
    bleee3333....
    }
    }

    What I want to do is move ble1, ble2, ble3 into bla1. Just like this :


    public class A {
    @Action public void bla1(){
    public static void ble1(){
    bleee1111....
    }
    public static void ble2(){
    bleee2222....
    }
    public static void ble3(){
    bleee3333....
    }
    }

    @Action public void bla2(){
    blaaa2222....
    }
    }

    Java IDE will reject it. How to solve ? Thank you in advance.
     
    tobleron, Nov 25, 2008
    #1
    1. Advertising

  2. tobleron

    Lord Zoltar Guest

    On Nov 25, 9:12 am, tobleron <> wrote:
    > Hi,
    >
    > I have 2 files.
    >
    > File A.java
    >
    > public class A {
    >    @Action public void bla1(){
    >       blaaa1111....
    >    }
    >    @Action public void bla2(){
    >       blaaa2222....
    >    }
    >
    > }
    >
    > File B.java
    >
    > public class B {
    >    public static void ble1(){
    >       bleee1111....
    >    }
    >    public static void ble2(){
    >       bleee2222....
    >    }
    >    public static void ble3(){
    >       bleee3333....
    >    }
    >
    > }
    >
    > What I want to do is move ble1, ble2, ble3 into bla1. Just like this :
    >
    > public class A {
    >    @Action public void bla1(){
    >       public static void ble1(){
    >          bleee1111....
    >       }
    >       public static void ble2(){
    >          bleee2222....
    >       }
    >       public static void ble3(){
    >          bleee3333....
    >       }
    >    }
    >
    >    @Action public void bla2(){
    >       blaaa2222....
    >    }
    >
    > }
    >
    > Java IDE will reject it. How to solve ? Thank you in advance.


    In Java, I think this is usually solved with inner classes.
    However, I would think it might just be better to declare ble* as
    private methods in class A rather than make them methods in inner
    classes declared in bla1
     
    Lord Zoltar, Nov 25, 2008
    #2
    1. Advertising

  3. tobleron

    Lew Guest

    On Nov 25, 9:12 am, tobleron <> wrote:
    > Hi,
    >
    > I have 2 files.
    >
    > File A.java
    >
    > public class A {
    >    @Action public void bla1(){
    >       blaaa1111....
    >    }
    >    @Action public void bla2(){
    >       blaaa2222....
    >    }
    >
    > }
    >
    > File B.java
    >
    > public class B {
    >    public static void ble1(){
    >       bleee1111....
    >    }
    >    public static void ble2(){
    >       bleee2222....
    >    }
    >    public static void ble3(){
    >       bleee3333....
    >    }
    >
    > }
    >
    > What I want to do is move ble1, ble2, ble3 into bla1. Just like this :
    >
    > public class A {
    >    @Action public void bla1(){
    >       public static void ble1(){
    >          bleee1111....
    >       }
    >       public static void ble2(){
    >          bleee2222....
    >       }
    >       public static void ble3(){
    >          bleee3333....
    >       }
    >    }
    >
    >    @Action public void bla2(){
    >       blaaa2222....
    >    }
    >
    > }
    >
    > Java IDE will reject it. How to solve ? Thank you in advance.


    <http://java.sun.com/developer/onlineTraining/>

    --
    Lew
     
    Lew, Nov 25, 2008
    #3
  4. tobleron

    heyx

    Joined:
    Nov 25, 2008
    Messages:
    17
    public class A {
    @Action public void bla1(){
    blaaa1111....
    //add this

    B b=new b();


    //
    }
    @Action public void bla2(){
    blaaa2222....
    }
    }
     
    heyx, Nov 26, 2008
    #4
  5. tobleron

    tobleron Guest

    >
    > In Java, I think this is usually solved with inner classes.
    > However, I would think it might just be better to declare ble* as
    > private methods in class A rather than make them methods in inner
    > classes declared in bla1


    Since I divided class A into several actions, I need to place ble*
    inside the action Bla1. That's why I'm not declare them as private
    methods in class A. I've tried to declare them as inner classes, but
    still doesn't work.
     
    tobleron, Nov 26, 2008
    #5
  6. tobleron

    tobleron Guest

    @All,

    The problem has been solved. I put Ble* inside the A class and make a
    call from Bla1.

    Thread closed.
     
    tobleron, Nov 26, 2008
    #6
  7. tobleron

    Lew Guest

    tobleron wrote:
    > @All,
    >
    > The problem has been solved. I put Ble* inside the A class and make a
    > call from Bla1.
    >
    > Thread closed.


    Just for future reference:

    - Java does not support methods within methods.
    - I, and maybe others, would like to know what went wrong with the inner-class
    approach. You said it "doesn't work" but didn't say what was wrong with it.

    --
    Lew
     
    Lew, Nov 26, 2008
    #7
    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. Jerry
    Replies:
    1
    Views:
    326
    Rajeev Soni
    Aug 4, 2003
  2. Jay
    Replies:
    1
    Views:
    298
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. walterd

    Navigation - Please Advise

    walterd, Apr 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    274
    walterd
    Apr 14, 2004
  4. =?Utf-8?B?Smlt?=

    User Control Problems, please advise...

    =?Utf-8?B?Smlt?=, Sep 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Sep 2, 2004
  5. Alan Silver

    Please advise about caching

    Alan Silver, Feb 10, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    418
    Alan Silver
    Feb 10, 2005
Loading...

Share This Page