Created
August 24, 2021 18:01
-
-
Save benhlal/10d390ec01c1439cef934d177e1ab459 to your computer and use it in GitHub Desktop.
pattern matching instanceof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Before | |
| if (person instanceof Student) { | |
| Student student = (Student) person; | |
| student.subscribeToCourse(); | |
| } | |
| //After | |
| if(obj instanceof Student student) student.subscribeToCourse(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment