Why shouldn't I use UNIVERSAL::isa?

前端 未结 7 1124
终归单人心
终归单人心 2021-02-07 07:58

According to this

http://perldoc.perl.org/UNIVERSAL.html

I shouldn\'t use UNIVERSAL::isa() and should instead use $obj->isa() or CLASS->isa().

This means

7条回答
  •  时光取名叫无心
    2021-02-07 08:25

    Update for 2020: Perl v5.32 has the class infix operator, isa, which handles any sort of thing on the lefthand side. If the $something is not an object, you get back false with no blowup.

    use v5.32;
    
    if( $something isa 'Animal' ) { ... }
    

提交回复
热议问题