# Inline Local Variables

# Description

According to the rule S1488 (opens new window) on the web site 'sonarcloud.io', local variables should not be declared and then immediately returned or thrown. Therefore this rule scans for local variables which are exclusively used in one single return- or throw statement and in-lines them if this is possible.

# Benefits

Simplifies code by removing unnecessary variable declarations.

# Tags

# Code Changes

# Variables In Return Statements

Pre

	int result = (a + b) * (c + d);
	return result;

Post

    return (a + b) * (c + d);

# Variables In Throw Statements

Pre

	RuntimeException exception = new RuntimeException(message, cause);
	throw exception;

Post

    throw new RuntimeException(message, cause);

🛠️ Auto-refactor Available

You can auto-refactor this with jSparrow.
Drop this button to your Eclipse IDE workspace to install jSparrow for free:

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client

Need help? Check out our installation guide.

# Properties

Property Value
Rule ID InlineLocalVariables
First seen in jSparrow version 4.19.0
Minimum Java version 1.1
Remediation cost 2 min
Links