MINOR: improve generic type safety for IQv2 in metered-store layer#21683
MINOR: improve generic type safety for IQv2 in metered-store layer#21683mjsax wants to merge 4 commits intoapache:trunkfrom
Conversation
mjsax
left a comment
There was a problem hiding this comment.
Highlighted the code changes -- other stuff is improved code formatting only.
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| verify(inner).init(context, store); |
There was a problem hiding this comment.
Totally unrelated side cleanup -- but doesn't make any sense to have a verify in @AfterEach -- this should just be part of the test, which is empty atm and "misuses" the teatDown() method to actually test what it should test...
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| verify(inner).init(context, store); |
| final Query<?> query, | ||
| public interface QueryHandler<R> { | ||
| QueryResult<R> apply( | ||
| final Query<R> query, |
There was a problem hiding this comment.
This is the key change -- If we get a Query with gives us result R, and we apply it, we should get a QueryResult<R> back -- And we thy the result type R to the QueryHandler interface.
Not using any types here, is unnecessarily loose I believe.
|
|
||
| @SuppressWarnings("rawtypes") | ||
| private final Map<Class, QueryHandler> queryHandlers = | ||
| private final Map<Class<?>, QueryHandler<?>> queryHandlers = |
There was a problem hiding this comment.
If we cannot have safe types, make it explicit using <?> (similar elsewhere)
| } | ||
| } else { | ||
| result = (QueryResult<R>) handler.apply( | ||
| result = ((QueryHandler<R>) handler).apply( |
There was a problem hiding this comment.
That we have improved type check on the the QueryHandler, we need to cast the handler, and get the correct result type automatically.
This is still cleaner. The issue is with the queryHandlers Map that introduces the missing types, so the "problem" is not at the right place in the code.
(similar elsewhere in this PR)
ebff123 to
26df811
Compare
26df811 to
0ef1fb1
Compare
No description provided.