#24 reflective: isInstance dla wildcards

닫힘
ranides5 년 전을 오픈 · 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 년 전
소유자

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 년 전에서 이 이슈 언급
로그인하여 이 대화에 참여
마일스톤 없음
담당자 없음
참여자 1명
로딩중...
취소
저장
아직 콘텐츠가 없습니다.