可以通过instanceof来判断实体类型,Demo如下示例:@Entry @Component struct TestPage1 { @State list :Array<Object> = [new Cat(), new Dog()] build() { Row() { Column() { ForEach(this.list,(item:Object) => { if (item instanceof Cat) { Text("this is Cat") } else if (item instanceof Dog){ Text("this is Dog") } }) } .width('100%') } .height('100%') } } class Cat{} class Dog{}
可以通过instanceof来判断实体类型,Demo如下示例: