Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Method inside method problem, please advise

Reply
Thread Tools

Method inside method problem, please advise

 
 
tobleron
Guest
Posts: n/a
 
      11-25-2008
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.
 
Reply With Quote
 
 
 
 
Lord Zoltar
Guest
Posts: n/a
 
      11-25-2008
On Nov 25, 9:12*am, tobleron <bud...@yahoo.com> 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
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      11-25-2008
On Nov 25, 9:12*am, tobleron <bud...@yahoo.com> 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
 
Reply With Quote
 
heyx heyx is offline
Junior Member
Join Date: Nov 2008
Posts: 17
 
      11-26-2008
public class A {
@Action public void bla1(){
blaaa1111....
//add this

B b=new b();


//
}
@Action public void bla2(){
blaaa2222....
}
}
 
Reply With Quote
 
tobleron
Guest
Posts: n/a
 
      11-26-2008
>
> 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.
 
Reply With Quote
 
tobleron
Guest
Posts: n/a
 
      11-26-2008
@All,

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

Thread closed.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      11-26-2008
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
 
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
Wireless Network help/advise needed please =?Utf-8?B?cGFmb3M=?= Wireless Networking 1 01-21-2006 05:30 PM
O.K. novice at work here!! Please advise.. =?Utf-8?B?Umljaw==?= Wireless Networking 8 12-24-2004 02:50 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM
Please Advise LSB MCSD 2 08-18-2003 12:08 PM
advise please damien crowe MCSE 4 07-25-2003 09:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57