ndimiduk commented on PR #6623:
URL: https://github.com/apache/hbase/pull/6623#issuecomment-2813134296
Sorry, I've been away for a while.
> The only thing that gets tricky here is that you need to do class casting
to get the exact class you care about. So for example ...
I was thinking about whether this could be made easier with generics. I
think the answer is yes, but we really don't want to make `Result` generic over
`QueryMetrics` and we don't have enough `Get`- or `Scan`-specific stuff to
justify specialising to a `GetResult extends Result` and `ScanResult extends
Result`.
So I thing the down-casting approach is fine. Maybe there's some helper
method that would make it a little safer? I.e., push the cast into methods
`Optional<GetMetrics> getGetMetrics()` and `Optional<ScanMetrics>
getScanMetrics()`. Or a single method with templates, like
```java
class Result {
QueryMetrics getQueryMetricsInternal() { ... }
<T extends QueryMetrics> Optional<T> getQueryMetrics() {
return Optional.ofNullable((T) getQueryMetricsInternal());
}
}
Result r = table.get(get);
GetMetrics getMetrics = r.<GetMetrics>getQueryMetrics();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]