Cannot refer to the non-final local variable productname defined in an enclosing scope

Probably you are using java 8 and the other computer is using java 7. Java requires references to variables from inner classes to be final variables. Java 8 will make them effectively final if you don’t reassign.

Cannot refer to the non-final local variable productname defined in an enclosing scope
Cannot refer to the non-final local variable productname defined in an enclosing scope

Probably you are using java 8 and the other computer is using java 7. Java requires references to variables from inner classes to be final variables. Java 8 will make them effectively final if you don’t reassign.

Solution

You need to change java 1.7 to java 1.8 in eclipse java compiler.

Select your project –> Right click –> Properties –> Java Compiler

Eclipse Java Compiler
Eclipse Java Compiler

The Author

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply