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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Veilok
Posts: 21
Joined: Sat Sep 01, 2018 10:53 am
Contact:

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

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

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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!

Veilok
Posts: 21
Joined: Sat Sep 01, 2018 10:53 am
Contact:

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

Post by Veilok »

My name is "edited", thank you!
Last edited by Veilok on Wed Apr 16, 2025 6:23 pm, edited 1 time in total.

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Great! It will be mentioned in the next version.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests