Skip to content

Instantly share code, notes, and snippets.

@juliofalbo
Last active May 19, 2021 10:05
Show Gist options
  • Save juliofalbo/5f3d50f8cd02baa7a33b838204590c3c to your computer and use it in GitHub Desktop.
Save juliofalbo/5f3d50f8cd02baa7a33b838204590c3c to your computer and use it in GitHub Desktop.
package main;
public class DeoptimizationExample {
public static void main(String[] args) {
for (int i = 0; i < 50000; i++) {
MyInterface myInterface;
if (i < 45000) {
// The first 45.000 executions will enter here
myInterface = new MyInterfaceImpl();
} else {
myInterface = new MyInterfaceLoggerImpl();
}
myInterface.addARandomNumber(50);
}
}
}
interface MyInterface {
void addARandomNumber(double value);
}
class MyInterfaceImpl implements MyInterface {
@Override
public void addARandomNumber(double value) {
double random = Math.random();
double finalResult = random + value;
}
}
class MyInterfaceLoggerImpl implements MyInterface {
@Override
public void addARandomNumber(double value) {
System.out.println("The value is: " + Math.random() + value);
}
}
@juliofalbo
Copy link
Author

Hi @renelink.

Sure, it is my pleasure!

Thank you for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment