Solved

Dont understand a method

Posted on 2006-10-26
8
187 Views
Last Modified: 2010-03-31

What is going on in this method? Even though its a void return type is has a return?  

  public void setVal(String val)
    {
        if (valr == null)
        {
            return;
        }
    }

Many thanks
0
Comment
Question by:prograMNewbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17809968
You can always have return. This method effectively does nothing though
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17809978
(as you wouldn't know from calling the method whether the String *was* null)
0
 

Author Comment

by:prograMNewbie
ID: 17809985

So is it the same as:

public void setVal(String val)
    {
        if (val == null)
        {
           
        }
    }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:hoomanv
ID: 17810049
YES
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 30 total points
ID: 17810057
We expect setVal to set some value for us
So that method is expected to do something like this

public void setVal(String val)
    {
        if (val == null)
        {
           throw new NullPointerException("non-null expected");
           // or throw new IllegalArgumentException("non-null expected");
        }
        // set the value here
    }
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 65 total points
ID: 17810074
And of course it's the same as

public void setVal(String val) {}
0
 
LVL 92

Assisted Solution

by:objects
objects earned 30 total points
ID: 17810135
So is it the same as:

public void setVal(String val)
    {
        if (val == null)
        {
           
        }
    }

It is but you wouldn't write it like that in case someone (and by the looks they will) decides to add code after the if
0
 

Author Comment

by:prograMNewbie
ID: 17810422

I see, thanks everyone ;)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question