[HD-OCP17/21-Fundamentals Pg 337, Sec. 13.3.4 - using-sealed-classes-and-interfaces]
Posted: Wed Feb 19, 2025 7:00 pm
I don't think this code is syntactically correct.
Code: Select all
FinancialInstrument fi = //get it somehow
switch(fi){
case fi instanceof Bond b -> valueBond(b);
case fi instanceof Stock s -> valueStock(s);
default -> throw new RuntimeException("Can't deal with this financial instrument!");
}