Solved

Dont understand a method

Posted on 2006-10-26
8
186 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 102
Glassfish admin console not working 1 32
Fast way to search item into Java Array (Rhino compatible) 2 31
Running JavaFX on the Raspberry Pi 27 40
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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