#23 reflective: match generics

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

net.ranides.assira.reflection.impl.RConstructorTest#testMatchGeneric

Mamy konstruktor public <R extends Number> Record(R param1, R param2).

Nie wiem czy istnieje jakakolwiek szansa, żeby w oparciu o type-bounds zaimplementować match. Chyba takie "super-elastic" metody będą po prostu bezużyteczne w przypadku reflective IClass. Normalnie to dużo prostsze przypadki nie przechodzą, więc płaczu nie ma.

net.ranides.assira.reflection.impl.RConstructorTest#testMatchGeneric Mamy konstruktor `public <R extends Number> Record(R param1, R param2)`. Nie wiem czy istnieje jakakolwiek szansa, żeby w oparciu o type-bounds zaimplementować `match`. Chyba takie "super-elastic" metody będą po prostu bezużyteczne w przypadku reflective IClass. Normalnie to dużo prostsze przypadki nie przechodzą, więc płaczu nie ma.
ranides повторно отвори преди 3 години
ranides коментира преди 3 години
Притежател

To be precise: it works correctly!

We match correct RWClass. We should NOT accept Integer constructors if we don't know the R. Even if R extends Number, it can be anything (for example R=Float!)

If we want to check if match generics works correctly for R extends Number, then we should search for a method with return type of R. We can check that.

Although it is not very useful, because java doesn't allow override return type, so filtering on return type is relatively pointless if we match by name.

To be precise: it works correctly! We match correct RWClass. We should NOT accept Integer constructors if we don't know the R. Even if R extends Number, it can be anything (for example R=Float!) If we want to check if match generics works correctly for R extends Number, then we should search for a method with return type of R. We can check that. Although it is not very useful, because java doesn't allow override return type, so filtering on return type is relatively pointless if we match by name.
ranides коментира преди 3 години
Притежател

We must be even more precise. It is not like that. We don't match for class parameter extending Number, but "free form" method param R. This method WILL match Integer, Float and other Double, because correct method will be "generated on the fly".

We need to think about semantic here. Current behavior is formally correct. Practically "free form method param" with extends should have "swapped" upper and lower bound.

We must be even more precise. It is not like that. We don't match for class parameter extending Number, but "free form" method param R. This method WILL match Integer, Float and other Double, because correct method will be "generated on the fly". We need to think about semantic here. Current behavior is formally correct. Practically "free form method param" with `extends` should have "swapped" upper and lower bound.
ranides коментира преди 3 години
Притежател

Solution is:

Don't use RFClass at all. Define correct specialization RMClass.

RMClass will work in "almost identical way" as RFClass.

Only difference is to swap upper and lower bound for RWClass if:

  • itype is RWClass (obviously)
  • generic type of RWClass is because of method parameter, not because of class
Solution is: Don't use RFClass at all. Define correct specialization RMClass. RMClass will work in "almost identical way" as RFClass. Only difference is to swap upper and lower bound for RWClass if: - itype is RWClass (obviously) - generic type of RWClass is because of method parameter, not because of class
ranides коментира преди 3 години
Притежател

OK. We solved this in much less overdesigned way. Inside RArgument we just pass data into FClass factory. Factory decides if we should swap bounds inside constructed RWClass.

We still use ordinary RFClass as a wrapper for a pair {type, annotated type}

OK. We solved this in much less overdesigned way. Inside RArgument we just pass data into FClass factory. Factory decides if we should swap bounds inside constructed RWClass. We still use ordinary RFClass as a wrapper for a pair `{type, annotated type}`
ranides посочи тази задача от ревизия преди 3 години
ranides посочи тази задача от ревизия преди 3 години
Впишете се за да се присъедините към разговора.
Няма етап
Няма изпълнител
1 участника
Зареждане...
Отказ
Запис
Все още няма съдържание.