Page 1 of 1

[HD-OCP17/21-Fundamentals Pg 337, Sec. 13.3.4 - using-sealed-classes-and-interfaces]

Posted: Wed Feb 19, 2025 7:00 pm
by Veilok
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!");
}

Re: [HD-OCP17/21-Fundamentals Pg 337, Sec. 13.3.4 - using-sealed-classes-and-interfaces]

Posted: Wed Feb 19, 2025 11:45 pm
by admin
You are right. It should be :

Code: Select all

switch(fi){
case Bond  b ->  valueBond(b); 
case Stock s -> valueStock(s);
default -> throw new RuntimeException("Can't deal with this financial instrument!");
}        
Please tell us your name so that you can be credited in the book.

thank you for your feedback!

Re: [HD-OCP17/21-Fundamentals Pg 337, Sec. 13.3.4 - using-sealed-classes-and-interfaces]

Posted: Thu Feb 20, 2025 4:56 pm
by Veilok
My name is "edited", thank you!

Re: [HD-OCP17/21-Fundamentals Pg 337, Sec. 13.3.4 - using-sealed-classes-and-interfaces]

Posted: Fri Feb 21, 2025 12:23 am
by admin
Great! It will be mentioned in the next version.