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!");
}