-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconsider recursive generics #54
Comments
In case you want to keep the recursive generics solution, please at least provide dynamic hit class where we can set hit type just like any other parameter. If other hit types can be converted to this dynamic hit type, it would allow processing of hits independently of the hit type. Here's an example: public static class AnyHit extends GoogleAnalyticsRequest<AnyHit> {
public AnyHit(GoogleAnalyticsRequest<?> original) {
for (Map.Entry<GoogleAnalyticsParameter, String> entry : original.getParameters().entrySet())
parameter(entry.getKey(), entry.getValue());
for (Map.Entry<String, String> entry : original.customDimensions().entrySet())
customDimensions.put(entry.getKey(), entry.getValue());
for (Map.Entry<String, String> entry : original.custommMetrics().entrySet())
customMetrics.put(entry.getKey(), entry.getValue());
}
} Any other hit class can be converted to |
If it's not clear how having <T extends GoogleAnalyticsRequest<T>> void process(T hit) { ... } Now they look like this: void process(AnyHit hit) { ... } And there are no more casting issues. |
Thank you for this suggestion. I added |
Hits typed as
T extends GoogleAnalyticsRequest<T>
are difficult to process. It creates situations where you have to castU extends GoogleAnalyticsRequest<U>
toT extends GoogleAnalyticsRequest<T>
. If I try to use justGoogleAnalyticsRequest<?>
, then the fluent setters returnObject
, which prevents setter chaining even when using only general parameters defined onGoogleAnalyticsRequest
.Consider dropping all classes derived from
GoogleAnalyticsRequest
and makingGoogleAnalyticsRequest
non-generic. Just put all parameter setters in this single class. It's less clean from OOP perspective, but it makes it much easier to implement generic hit processing code while keeping actual hit code as clean as it was before.The text was updated successfully, but these errors were encountered: