#24 reflective: isInstance dla wildcards

Kapalı
ranides tarafından 5 yıl önce kere açıldı · 2 yorum
ranides 5 yıl önce olarak yorumlandı

net.ranides.assira.reflection.impl.RWClassTest#testParent

Rzecz w tym, że my tu mamy unresolved params, bo przekazujemy obiekt (i type erasure wchodzi). A to oznacza, że NIE powinno tutaj nic matchować na ten moment, o ile nie zrobimy obsługi prawdziwej dla atrybutu IAttribute.RESOLVED.

Tylko w takim wypadku możemy być "tolerancyjniejsi" względem erasure'owanych typów i je przepuszczać

Test dla wildcardów powinien opierać się na isSuper/isSubclass dla TypeToken jako argumentu, bo on zawiera całe info na temat typu testowanego

//        System.out.printf("%s%n", ic1);
//        assertTrue(ic1.isInstance(new ArrayList<Float>())); 
`net.ranides.assira.reflection.impl.RWClassTest#testParent` Rzecz w tym, że my tu mamy unresolved params, bo przekazujemy obiekt (i type erasure wchodzi). A to oznacza, że NIE powinno tutaj nic matchować na ten moment, o ile nie zrobimy obsługi prawdziwej dla atrybutu `IAttribute.RESOLVED`. Tylko w takim wypadku możemy być "tolerancyjniejsi" względem erasure'owanych typów i je przepuszczać Test dla wildcardów powinien opierać się na isSuper/isSubclass dla TypeToken jako argumentu, bo on zawiera całe info na temat typu testowanego ``` // System.out.printf("%s%n", ic1); // assertTrue(ic1.isInstance(new ArrayList<Float>())); ```
ranides 3 yıl önce olarak yorumlandı
Sahibi

idea is simple, we : net.ranides.assira.reflection.impl.RCompareUtils#isSuper should deduce argument "raw". It should be true only if:

raw = raw || !isuper.isResolved() || !iclass.isResolved(); 
idea is simple, we : net.ranides.assira.reflection.impl.RCompareUtils#isSuper should deduce argument "raw". It should be true only if: ``` raw = raw || !isuper.isResolved() || !iclass.isResolved(); ```
ranides 3 yıl önce işlemesinde bu sorunu işaret etti
ranides 3 yıl önce olarak yorumlandı
Sahibi

We preserve information attribute if type is resolved. We are permisive when we check type relations (equal, super, subclass) if one of the types is not resolved.

All in all, we should be permisive because compiler does the same, because of type erasure. It is classical unchecked cast, it is allowed by Java, so let's allow it too.

We could do the opposite: return false if we are not sure. Or even better: throw exception with information, that we are unable to check. Maybe we can implement that in some "strict mode", but at this moment, such strict mode seems to be useless.

todo: strict mode

We preserve information attribute if type is resolved. We are permisive when we check type relations (equal, super, subclass) if one of the types is not resolved. All in all, we should be permisive because compiler does the same, because of type erasure. It is classical unchecked cast, it is allowed by Java, so let's allow it too. We could do the opposite: return false if we are not sure. Or even better: throw exception with information, that we are unable to check. Maybe we can implement that in some "strict mode", but at this moment, such strict mode seems to be useless. todo: strict mode
ranides 3 yıl önce yeniden açtı
ranides 3 yıl önce işlemesinde bu sorunu işaret etti
Giriş yap bu konuşmaya katılmak için.
Kilometre Taşı Yok
Atanan Kişi Yok
1 Katılımcı
Yükleniyor...
İptal
Kaydet
Henüz bir içerik yok.