【语法BUG】Variable used in lambda expression should be final or effectively final

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43227967/article/details/90511084

table of Contents

First, the original error:

Second, the translation error:

Third, the source of the error:

3.1, use variables within Lambda external abnormalities

3.2, using variable external thread of abnormal

Fourth, the solution


First, the original error:

Variable used in lambda expression should be final or effectively final

Second, the translation error:

Variable lambda expressions used should be final or effective final 

Third, the source of the error:

3.1, use variables within Lambda external abnormalities

Note: Although here is Lambda expressions using variables should be final, but in fact the problem also occurs in the thread.

 

3.2, using variable external thread of abnormal

Note the threads here in fact with just a shorthand for a prototype Lambda nothing.

Fourth, the solution

Define a variable value, equal to i, and then to the internal thread to use in jdk1.8 is able to identify and does not throw an exception, but if you write the value ++ program will continue to be thrown under warning

 After using the value ++ program throws an exception

 

Guess you like

Origin blog.csdn.net/qq_43227967/article/details/90511084