I'm going through my code to make sure it conforms to CheckStyle standards.
I personally feel that the rule "No Inner Assignments" makes the code more complicated to understand (you have to look in 3 places instead of 1).
Is there some way that I could preserve my single area by creating a {} block within the while loop to perform my assignments and return a boolean?!
What are your opinions?
File file = new File("C:\\test.txt");
FileInputStream fileInputStream = new FileInputStream(new FileInputStream(file));
// Inner Assignment
while ((int i = fileInputStream.readLine()) != -1)
{
//
}
// No Inner Assignment
int i = fileInputStream.readLine();
while(i!= -1)
{
//
i = in.readLine();
}
I encounter similar issues when I require a while loop which assigns a combination of some variable using, for example the ++ operator.
Would this for loop be considered a better alternative (it does comply with checkstyle)
for (int i = fileInputStream.readLine(); i != -1; i = fileInputStream.readLine())
{
//
}