You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot evaluate the instance of anonymous class #1163
Hi, I have a similar problem with internal field initializer.
import java.util.*;
public class RomanToInteger {
public int romanToInt(String s) {
var ri = new HashMap<Character,Integer>() {{
put('I', 1);
}};
var c = ri.get(s.charAt(0)); // ri returns cannot evaluate
return 0;
}
}
Environment
Operating System: Win 11
JDK version: openjdk version "11.0.12" 2021-07-20
Java extension version: Language Support for Java(TM) by Red Hat 0.40.1
Java Debugger extension version: 0.40.1
Visual Studio Code Version: 1.67.1
Commit: da15b6fd3ef856477bf6f4fb29ba1b7af717770d
Hi Jinbo Wang (@testforstephen), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
During debugging, the console evaluates expressions in the context of the current frame—which, inside a double-brace initializer, is the anonymous class—so your local variable ri isn’t in scope there. Workarounds:
Extract the map initialization outside the anonymous class:
These approaches ensure ri is visible to the debug console. You can still inspect the map via the VARIABLES view if you prefer.
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!
Activity
github-actions commentedon Nov 11, 2025
Hi Jinbo Wang (@testforstephen), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
During debugging, the console evaluates expressions in the context of the current frame—which, inside a double-brace initializer, is the anonymous class—so your local variable
riisn’t in scope there. Workarounds:These approaches ensure
riis visible to the debug console. You can still inspect the map via the VARIABLES view if you prefer.The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!