Ever wondered how the JVM debugger 'Evaluate' feature works in IDEs? Long ago I thought that the Java debug interface (JDI) actually allows you to specify the expression and get back its value.

However, this is not quite possible: there's no Java language compiler inside the JVM. When the process is paused JDI allows you to read or write any variables and fields or even execute an existing method with given arguments. But nothing like addition or multiplication.
On the other hand, #IntelliJIDEA debugger allows you to evaluate even statements! You can write there `for`, `if`, `while`, `switch` - whatever. You can even declare local variables. So how this works?
The answer is simple: IDEA debugger has a built-in interpreter for Java! If you access an existing variable or a field, call a method or instantiate an object, it queries JDI. Otherwise, IDE itself does all the calculations.
The amusing thing is that debugger authors didn't bother to make it as strict as Java itself, so the language inside the interpreter is a much more permissive version of Java. For example, you don't need to initialize variables there! Default values like 0 are used automatically.
Of course, final variables could be changed. Why artificial limitations?
Another thing: most of the casts are not necessary. This interpreted Java more resembles dynamically typed languages like JavaScript. Duck-typing works: if there's a method, we can call it. Even if the highlighter complains.
Switch statements and expressions are more permissive there: you can switch over any type. Also, no default is necessary for switch expressions. If it's not visited, the evaluation will be successful.
In addition to use any type, you can use any expressions as case labels, not just constants! The first matching branch will be executed.
Finally, even if your project still uses Java 6 JDK, it doesn't stop you from using new language features. For example, 'var' declarations and patterns in instanceof work perfectly, because they are interpreted by IDE, not by your JDK. Just ignore error messages!

More from Tech

On Wednesday, The New York Times published a blockbuster report on the failures of Facebook’s management team during the past three years. It's.... not flattering, to say the least. Here are six follow-up questions that merit more investigation. 1/

1) During the past year, most of the anger at Facebook has been directed at Mark Zuckerberg. The question now is whether Sheryl Sandberg, the executive charged with solving Facebook’s hardest problems, has caused a few too many of her own. 2/
https://t.co/DTsc3g0hQf


2) One of the juiciest sentences in @nytimes’ piece involves a research group called Definers Public Affairs, which Facebook hired to look into the funding of the company’s opposition. What other tech company was paying Definers to smear Apple? 3/ https://t.co/DTsc3g0hQf


3) The leadership of the Democratic Party has, generally, supported Facebook over the years. But as public opinion turns against the company, prominent Democrats have started to turn, too. What will that relationship look like now? 4/

4) According to the @nytimes, Facebook worked to paint its critics as anti-Semitic, while simultaneously working to spread the idea that George Soros was supporting its critics—a classic tactic of anti-Semitic conspiracy theorists. What exactly were they trying to do there? 5/

You May Also Like

ARE WE FAMILIAR WITH THE MEANING & POWER OF MANTRAS WE CHANT?

Whenever we chant a Mantra in Sanskrit, it starts with 'Om' and mostly ends with 'Swaha' or 'Namaha'. This specific alignment of words has a specific meaning to it which is explained in Dharma Shastra.


Mantra is a Sanskrit word meaning sacred syllable or sacred word. But Mantras r not just words put together,they r also vibrations.The whole Universe is a cosmic energy in different states of vibration &this energy in different states of vibration forms the objects of Universe.

According to Scriptures,Om is considered to be ekaakshar Brahman,which means Om is the ruler of 3 properties of creator,preserver&destroyer which make the
https://t.co/lyhkWeCdtv is also seen as a symbol of Lord Ganesha, as when starting the prayer,it's him who is worshipped 1st.


'Om' is the sound of the Universe. It's the first original vibration of the nothingness through which manifested the whole Cosmos. It represents the birth, death and rebirth process. Chanting 'Om' brings us into harmonic resonance with the Universe. It is a scientific fact.

Therefore, Mantras are described as vibrational words that are recited, spoken or sung and are invoked towards attaining some very specific results. They make very specific sounds at a frequency that conveys a directive into our subconcious.