dcsimg
getting a return value from a void method
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Pat_Adewunmi
Posted On:   Monday, April 8, 2002 06:42 PM

I implemented a method from an Interface, the method return type is void. After I provided my implementation I actually need to return a String type after my processing. How can I do this? Since I cannot change the return type of the method that I inherited from the Interface. The approach I took was to define a static class variable and a method to return the value of that class variable. The value I want to return is then assigned to this class variable in my implementation. I then call the get method but the value the method returns is the original initialized value of the variable. Any suggestion of how to get the final value would be helpful. Thanks in advance.    More>>


I implemented a method from an Interface, the method return type is void. After I provided my implementation I actually need to return a String type after my processing. How can I do this?
Since I cannot change the return type of the method that I inherited from the Interface.

The approach I took was to define a static class variable and a method to return the value of that class variable.

The value I want to return is then assigned to this class variable in my implementation.

I then call the get method but the value the method returns is the original initialized value of the variable.


Any suggestion of how to get the final value would be helpful. Thanks in advance.

   <<Less

Re: getting a return value from a void method

Posted By:   shautvas_t  
Posted On:   Wednesday, April 10, 2002 12:27 AM

approach seems OK

run this:

public class T

{

static String x="initial";



public static void main(String[] args)

{

System.out.println(x);

T instance=new T();

instance.change();

System.out.println(x);

}


public void change()

{

x="final";

}

}


It works fine. Test if your method to change the static variable is actually called.
About | Sitemap | Contact