#24 reflective: isInstance dla wildcards

Geschlossen
vor 5 Jahren geöffnet von ranides · 2 Kommentare
ranides kommentierte vor 5 Jahren

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 kommentierte vor 3 Jahren
Besitzer

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 hat vor 3 Jahren geschlossen
ranides hat dieses Issue vor 3 Jahren aus einem Commit referenziert
ranides kommentierte vor 3 Jahren
Besitzer

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 hat vor 3 Jahren wieder geöffnet
ranides hat dieses Issue vor 3 Jahren aus einem Commit referenziert
ranides hat vor 3 Jahren geschlossen
Anmelden, um an der Diskussion teilzunehmen.
Kein Meilenstein
Niemand zuständig
1 Beteiligte
Laden…
Abbrechen
Speichern
Hier gibt es bis jetzt noch keinen Inhalt.