Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA: execute selected fragment of code

Sometimes there is a need to quickly test some expression's output. It would be convenient to execute selected fragment and see the result instantly in System.out without running project's main() method.

Is there some workaround for IntelliJ to provide this feature?

like image 912
Oleg Mikhailov Avatar asked Apr 13 '16 07:04

Oleg Mikhailov


People also ask

What is Ctrl Alt L in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.

How do I skip parts of a program while debugging IntelliJ?

To ignore a script when stepping through the program during a debugging session, configure a stepping filter. Select this checkbox to have IntelliJ IDEA inform you every time it receives a request to a script to be skipped. This list shows the scripts and folders to ignore requests to.


1 Answers

The easiest way is just to stop a debug before what you are trying to test, press ALT + F8 and execute the expression on the window that appears.

You are going to have access to everything declared to that point, so you can execute anything without changing the state of your code.

like image 76
dambros Avatar answered Oct 13 '22 13:10

dambros