1

I wrote a small program to check the given movie name exist in a folder. I am getting the warning on eclipse "the value of local variable is not used"

Here is the main method

public static void main(String[] args) {
        // TODO Auto-generated method stub
        boolean movie_exist=false;

        System.out.println("Hellow world!");

        try{

        FileWriting newfolrder = new FileWriting("H:\\breakinbad2\\Breaking Bad Season 2 Complete 720p.BRrip.Sujaidr");
        //movie_exist=newfolrder.checkfilesname("Movie name");
        System.out.println(newfolrder.checkMovieExist("Breaking Bad"));
        movie_exist = newfolrder.checkMovieExist("Breaking Bad");

        }catch(NullPointerException e){
            System.out.println("Exception is :"+ e);
        }

    }

I get the warning against this variable declaration

boolean movie_exist=false;

I have assign a value to the variable.

movie_exist = newfolrder.checkMovieExist("Breaking Bad");

Why do I get this warning?

2
  • 1
    the false value assigned to movie_exist is never used before it is overwritten. Commented Sep 20, 2014 at 18:13
  • It completely ethical and legal as long as you have permission from the rights holder. Commented Sep 20, 2014 at 19:02

2 Answers 2

3

Because you assigned and re-assigned the variable but never actually used it anywhere.

So if you removed this variable definition it wouldn't affect the code. You have to use it in an if condition, method call, etc. in order for the warning to disappear

Sign up to request clarification or add additional context in comments.

Comments

1

What would happen if you completely removed the use of movie_exist? Nothing, your application would work exactly the same way.

You've never used movie_exist as an expression that resolves to a value, so it warns you about it so that you may remove it or start using it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.