I'm integrating Project Lombok in our Android app. I'm running into issues with using val and var. I'm getting Incompatible Types error for a field of type var or val, when I assign a value (of any type) to it.
private final val example = new ArrayList<String>();
private var eg2;
eg2=getRandomString();
Has anyone tried var and val in Android? Any help would be appreciated.
I'm using Lombok version 1.16.12 ,Android Studio 2.3 Beta 1, Android Plugin version 2.2.3, and Gradle 3.2.1.
I think I can see your issue -
@val
and@var
only work for local variables - that is variables within a method or block.So the following will work:
But it won't work with class members (this won't build):
@var
also needs to be manually enabled. To do this add alombok.config
to your project with the contents: