Однако, начиная с Java SE 8, локальный класс может обращаться к локальным переменным и параметрам> закрывающего блока, которые являются окончательными или фактически окончательными.
blockquote>Это не начать с Java 8, я использую это с давних пор. Этот код использовал (до java 8), чтобы быть законным:
String str = ""; //<-- not accesible from anonymous classes implementation final String strFin = ""; //<-- accesible button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String ann = str; // <---- error, must be final (IDE's gives the hint); String ann = strFin; // <---- legal; String str = "legal statement on java 7," +"Java 8 doesn't allow this, it thinks that I'm trying to use the str declared before the anonymous impl."; //we are forced to use another name than str } );