changeset 90:9e9304700312

fix DataGear check type interface and superclass
author akahori
date Sat, 15 Sep 2018 11:19:11 +0900
parents 2c22b23fa725
children 31325aff1d8b
files src/main/java/christie/datagear/dg/DataGear.java
diffstat 1 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/christie/datagear/dg/DataGear.java	Sat Sep 15 10:34:04 2018 +0900
+++ b/src/main/java/christie/datagear/dg/DataGear.java	Sat Sep 15 11:19:11 2018 +0900
@@ -24,10 +24,26 @@
 
     public void setData(T data) {
         Class dataClazz = data.getClass();
-        if (dataClazz == this.clazz ||
-                dataClazz.getSuperclass() == this.clazz){
-            this.data = data;
+
+        if(dataClazz == this.clazz){
+            this.data = data; return;
         }
+
+        Class dataSuperClazz = dataClazz.getSuperclass();
+        while (dataSuperClazz != null) {
+            if(dataSuperClazz == this.clazz) {
+                this.data = data; return;
+            }
+            dataSuperClazz = dataSuperClazz.getSuperclass();
+        }
+
+        Class<?>[] interfaces = dataClazz.getInterfaces();
+        for (Class<?> interfaze : interfaces) {
+            if(interfaze == this.clazz) {
+                this.data = data; return;
+            }
+        }
+
     }
 
     public void setClazz(Class clazz){