if(objectName instanceof Mammal currentMammal){
currentMammal.shedHair();
if the (objectName instanceof Mammal) is true then currentMammal is casted to Mammal. I see this works, but dont know how. I have never seen this stuff going on in "if" statements
I believe this makes sense.
if (ao instanceof Mammal) {
Mammal currentMammal = (Mammal) ao;
currentMammal.shedHair();
}
but this first snippet is over my head
Got the answer. https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof-operator.html#GUID-843060B5-240C-4F47-A7B0-95C42E5B08A7.
This is a new feature added in JDK 16.