Just to clarify, this was fixed by doing the following:
I went into the Project menu – > Properties → Java… enabled project specific settings… and there’s a “compliance level” setting. For me, it was set to 16. I changed it to 11, and debugging now worked.