Skip to content
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

Missing Collection Type Parameter Declarations for method return values? #1113

Open
micycle1 opened this issue Jan 26, 2025 · 7 comments
Open

Comments

@micycle1
Copy link
Contributor

micycle1 commented Jan 26, 2025

Many areas of the codebase return collections without a type parameter declaration (examples below), which introduces the need for superfluous casting in user's code.

Happy to do this myself (at least on the more commonly used areas) -- would you accept a PR for this?

Image

@dr-jts
Copy link
Contributor

dr-jts commented Jan 27, 2025

This has come up before - see #492.

@jodygarnett do you have any concerns with this? (since GeoTools is a good proxy to determine what effect this will have on client code).

Not directly related to this proposal: discussions and work on adding type parameters to JTS containers: #146, #777, #797 and #799.

@jodygarnett
Copy link
Contributor

jodygarnett commented Jan 27, 2025

Yes, it would be a good idea to add types to the lists, while type eraser is "weak" in Java ... it is still something and can help catch mistakes before runtime.

@micycle1 if you are in position to work on this is would be a welcome addition to the library. We would issue a new dot release (due to API change).

@dr-jts
Copy link
Contributor

dr-jts commented Jan 27, 2025

@micycle1 How about you start with a PR to add generics to a small number of classes (perhaps just one?) so we can assess how this will work?

@dr-jts
Copy link
Contributor

dr-jts commented Jan 27, 2025

Also note #797. Perhaps @halset will be willing to rebase that PR so it can be merged?

@micycle1
Copy link
Contributor Author

@micycle1 How about you start with a PR to add generics to a small number of classes (perhaps just one?) so we can assess how this will work?

The issue I’m referring to isn’t about adding generics to classes (like initialising STRTree with a type, as suggested in the other linked issues). Instead, it’s about ensuring that methods return properly typed values wherever it makes sense.

For example, take the method SegmentStringUtil.extractBasicSegmentStrings(). It currently returns a List of BasicSegmentString objects, but it doesn’t specify the type explicitly. I’m suggesting it should return List<SegmentString> instead of just a raw List. This would make the return type clearer and improve type safety for anyone using the method.

That said, adding generics is a good idea too. I can do that, but it's probably best to use #797 (as you've pointed out) as a starting point.

@dr-jts
Copy link
Contributor

dr-jts commented Jan 27, 2025

The issue I’m referring to isn’t about adding generics to classes (like initialising STRTree with a type, as suggested in the other linked issues). Instead, it’s about ensuring that methods return properly typed values wherever it makes sense.

Good clarification. I'll update the comment above about related issues to make that clear. I've updated the issue title to clarify as well - feel to improve if needed.

@dr-jts dr-jts changed the title Missing Type Parameter Declarations Missing Collection Type Parameter Declarations for method return values? Jan 27, 2025
@jodygarnett
Copy link
Contributor

jodygarnett commented Jan 28, 2025

Small feedback on issue title:

Add Type Parameter declarations for method return values

Turns it into a "positive improvement" rather than a mistake being fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants