Method inside method problem, please advise

T

tobleron

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

Lord Zoltar

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
 
L

Lew

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/>
 
Joined
Nov 25, 2008
Messages
17
Reaction score
0
public class A {
@Action public void bla1(){
blaaa1111....
//add this

B b=new b();


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

tobleron

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

tobleron

@All,

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

Thread closed.
 
L

Lew

tobleron said:
@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.
 

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

Forum statistics

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

Latest Threads

Top