How to tell if an object is an instance of a class

后端 未结 3 1562
时光说笑
时光说笑 2021-02-02 07:45

How can I determine whether an object is of a class or not in the Dart language?

I\'m looking to do something like the following:

if (someObject.class.to         


        
3条回答
  •  孤城傲影
    2021-02-02 08:08

    Here is a simple explanation with a solution.

    You have:

    Object obj =t1;
    where t1 is an object of class T.

    And you have other object T called t.

    T t = new T();

    How to check if obj is the same type of t ?

    Solution:

    if(obj is t)
         print('obj is typeof t')
       else print('obj is not typeof t') 
    

提交回复
热议问题