# InstanceOf instead of switch case in CheckoutController

**URL:** <https://forum.codewithmosh.com/t/instanceof-instead-of-switch-case-in-checkoutcontroller/71474>\
**Category:** Java\
**Created:** [September 7, 2025, 5:35am UTC](https://forum.codewithmosh.com/t/instanceof-instead-of-switch-case-in-checkoutcontroller/71474 "2025-09-07T05:35:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tclaus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tclaus/32/14296_2.png) [@tclaus](https://forum.codewithmosh.com/u/tclaus)\
**Post date:** [September 7, 2025, 5:35am UTC](https://forum.codewithmosh.com/t/instanceof-instead-of-switch-case-in-checkoutcontroller/71474/1 "2025-09-07T05:35:21Z")

</div>

Hi Mosh -

Thanks for this great course series. I absolute like your style - for me it’s the best way to learn things I did not know until now.

BTW:

In “Spring Boot: Mastering REST API Development”, “Payment Processing”, Chapter 9, ~at minute 3:  
You made a switch-case block to check the eventType before casting the stripeObject. Is a modern instanceOf better?  
`if (stripeObject instanceof PaymentIntent paymentIntent) {...`

After this line you’ll get a paymentIntent correctly casted and null checked. Will this work?

---

<div class="post-metadata">

**Author:** ![tclaus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tclaus/32/14296_2.png) [@tclaus](https://forum.codewithmosh.com/u/tclaus)\
**Post date:** [September 7, 2025, 7:00pm UTC](https://forum.codewithmosh.com/t/instanceof-instead-of-switch-case-in-checkoutcontroller/71474/2 "2025-09-07T19:00:08Z")

</div>

As I am moving on in the course, I see now that in the next “refactoring” lesson the switch is needed to identify the type of event - not the type of the StripeObject. So the switch case and the utility method “extractOrder” is the best and shortest way to (for me) to do the job.
