#24 reflective: isInstance dla wildcards

Lezárt
megnyitva ekkor: 5 éve ranides által · 2 hozzászólás
ranides hozzászólt 5 éve

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 hozzászólt 3 éve
Tulajdonos

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 lezárta ekkor: 3 éve
ranides hivatkozott erre a hibajegyre egy commit-ban ekkor: 3 éve
ranides hozzászólt 3 éve
Tulajdonos

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 kinyitotta ekkor: 3 éve
ranides hivatkozott erre a hibajegyre egy commit-ban ekkor: 3 éve
ranides lezárta ekkor: 3 éve
Jelentkezzen be hogy csatlakozhasson a beszélgetéshez.
Nincs mérföldkő
Nincs megbízott
1 Résztvevő
Töltés...
Mégse
Mentés
Még nincs tartalom.