jdk 17 lombok 1.18.24 using import lombok.var illegal reference to restricted type 'var'

2,206 views
Skip to first unread message

Michael Rodgers

unread,
Jan 15, 2023, 11:25:37 PM1/15/23
to Project Lombok
I searched around to find reference to this error in group discussion but couldn't find much.

Specifically when I try to import lombok.var; I get the following error:
error: illegal reference to restricted type 'var'
import lombok.var;
             ^

I am using jdk 17, and lombok 1.18.24.  I created a stackoverflow on this issue as well which details on the gradle files and so forth.  

Thanks in advance.

Mike

Reinier Zwitserloot

unread,
Jan 15, 2023, 11:28:58 PM1/15/23
to Project Lombok
As the error says, `var` is a java keyword that is illegal to use as a type name. Starting with.... java 10? Certainly java 11, `var` is now just a java keyword (and with it, lombok's var is unusable). Prior to java 10, var was a valid name for an identifier; lombok.var exists _only_ to cater to java8 users who want to get a jump on using `var`, even. If we drop java8 support (given that we still support java6, odds are we won't for another decade), we'd kill var along with it.

Simply remove `import lombok.var` and nothing else has to change (all your existing uses of lombok's var now just turn into java's var). We designed it intentionally that way. We can't do anything about that import error, though.

Reply all
Reply to author
Forward
0 new messages