As of occasion you may need to ensure some Java code is never inlined when debugging performance problems.
The following hack works around this by abusing a special exception for the Throwable constructor.
static T dontinline(Supplier supplier) {
return (T) new Throwable() {
Object sneak = supplier.get();
}.sneak;
}
Top comments (0)