How to deal with " cannot assign a value to final variable"?

376 views
Skip to first unread message

Crabax

unread,
Apr 3, 2016, 7:20:49 PM4/3/16
to Project Lombok
Hello,

I want some help, I'm initiating on Android Studio and I want to do the fololwing:

val infoString = "";
if (!Backend.HasErrors()) {
   
for (val budgetPlan : planningInfo) {
       
infoString += budgetPlan.getMonth() + "[" + budgetPlan.getNumber() + "]: " + budgetPlan.getDescription();
   
}
}

But the compilation is throwing the following:
Error:(62, 17) error: cannot assign a value to final variable infoString

How can I do what I want without specify "String infoString = """?

Thanks in advance

Viacheslav Blinov

unread,
Apr 3, 2016, 7:45:12 PM4/3/16
to project...@googlegroups.com

You can't do this with @val. @val expands to "final T", and final means no reassignment, hence the name - val, not var. Perhaps somebody would come with @var proposal but for now it looks like you have to use explicit String instead

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages