Solved

Dont understand a method

Posted on 2006-10-26
8
179 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
  • 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
 
LVL 14

Expert Comment

by:hoomanv
ID: 17810049
YES
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now