Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

In IntelliJ Idea, what does "Extract Variable" do?

And how does it know how to replace "SongRequest.getSong()" with "song"?

When performing the operation, "song" was chosen automatically. We weren't offered any other choice.

1 Answer

I don't know what video or challenge you are referring too, but extract variable creates a variable from an expression.

Example:

        int i = 0;
        if (i != 0) {

        }

If you extract the variable in the above expression, you can get:

        int i = 0;
        boolean b = i != 0;
        if (b) {

        }

In other words, you create a new variable. I hope this clears it up :)