• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two methods into one  RSS feed

 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two methods that have exact same conditions but dfferent return values. Anyway to combine these two methods into one and still have two different values?


[ May 29, 2007: Message edited by: Mike Jenkins ]
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this code compile?

Kaydell
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i tried your program,the solution with which i have come up is shown below.


public class Method1 {
String fieldOne =null;
String fieldTwo=null;
String aField="";
String bField="";
String firstSetting = "";
String secondSetting = "";

public void Method2(String firstSetting,String secondSetting)
{
this.firstSetting=firstSetting;
this.secondSetting=secondSetting;
}
public void methodOne()
{
if ((fieldOne == null) && (fieldTwo != null) )
{
firstSetting = "firstSetting value: " + aField + " another part of firstSetting";
secondSetting = "secondSetting value " + aField;

}
else if ((fieldOne != null) && (fieldTwo == null) )
{

firstSetting = "firstSetting value " + bField + " another part of firstSetting";
secondSetting = "secondSetting value: " + bField;

}
else if ((fieldOne != null) && (fieldTwo != null) )
{
firstSetting = "firstSetting value " + bField + " another part of firstSetting " + aField;
secondSetting = "secondSetting value: " + bField + " and " + aField;
}

Method2(firstSetting,secondSetting);

}

public static void main(String[] args) {
Method1 m=null;
m.methodOne();

}

}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!