validate te code please

Discuss the validity of the following code:String s = buildMyString();if (s == null) {s = buildMyString();}
[142 byte] By [geetha_ind123a] at [2007-11-26 17:13:17]
# 1

it's pointless? s= doSomethong, if s != null, doSomething (again)?

In the else you would perform something new or different not call the very same method that generated the value in the firt place.

Also be more specifc in your posts. Whats yoru problem?

Message was edited by:

kikemelly

kikemellya at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 2

> Discuss the validity of the following code:

> String s = buildMyString();

> if (s == null) {

> s = buildMyString();

> }

It's useless! if you call BuildMyString() and you get a null, after that if you call it again you'll get a null again (this analysis based on your code sequence)!

regards

Manuel Leiria

manuel.leiriaa at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 3
It's a valid Java fragment. The name "buildMyString" should not be used in a real application.
DrClapa at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 4

> It's a valid Java fragment. The name "buildMyString"

> should not be used in a real application.

You are corect. I just thought about it. String s has no value onthe first call, it then calls buildMyString for a value. Then it checks whether it is null or not then calls buildMyString again. I hope the OP's buildMyString acts differently for non null Strings and performs something new, otherwise this would be of no use. But I guess it must do and this is of some use.

i got a lot to learn..

EDIT: ****, I get it now thanks to the last post. The else mthod keeps checking until its not null based on the conditions in the other method.

Message was edited by:

kikemelly

kikemellya at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 5

> > Discuss the validity of the following code:

> > String s = buildMyString();

> > if (s == null) {

> > s = buildMyString();

> > }

>

> It's useless! if you call BuildMyString() and you get

> a null, after that if you call it again you'll get a

> null again (this analysis based on your code

> sequence)!

Objection, your honor. Assumptions based on facts not in

evidence. Below is one simple example of why you are incorrect.

Don't even get me started on multithreading weirdness.

==DrClap

public String buildMyString() {

final long currentTimeMillis = System.getCurrentTimeMillis();

if ((currentTime / 2000d) == 0) {

return null;

}

return "Built!";

}

es5f2000a at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 6

> > > Discuss the validity of the following code:

> > > String s = buildMyString();

> > > if (s == null) {

> > > s = buildMyString();

> > > }

> >

> > It's useless! if you call BuildMyString() and you

> get

> > a null, after that if you call it again you'll get

> a

> > null again (this analysis based on your code

> > sequence)!

>

> Objection, your honor. Assumptions based on facts

> not in

> evidence. Below is one simple example of why you are

> incorrect.

> Don't even get me started on multithreading

> weirdness.

> ==DrClap

>

> > public String buildMyString() {

> final long currentTimeMillis =

> System.getCurrentTimeMillis();

>if ((currentTime / 2000d) == 0) {

>return null;

> }

>return "Built!";

>

>

ok, you've got a point.I didn't thought in that way

regards,

Manuel Leiria

manuel.leiriaa at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...
# 7
Please to tell me why now we must be doing your school assignment, also?
ParvatiDevia at 2007-7-8 23:41:13 > top of Java-index,Java Essentials,Java Programming...