#24 reflective: isInstance dla wildcards

Затворено
отворено пре 5 година од ranides · 2 коментара
ranides коментирира пре 5 година

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 година
Власник

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 година
ranides поменуо овај задатак у комит пре 3 година
ranides коментирира пре 3 година
Власник

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 година"
ranides поменуо овај задатак у комит пре 3 година
ranides затворено пре 3 година
Пријавите се да се прикључе у овом разговору.
Нема фазе
Нема одговорних
1 учесника
Учитавање...
Откажи
Сачувај
Још нема садржаја.