| Summary: | Inheritance where methods use a generic parameter as their return type fails. | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Niels Basjes <eclipse> | ||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | major | ||||||
| Priority: | P3 | CC: | stephan.herrmann | ||||
| Version: | 4.7.1a | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Linux | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
|
Description
Niels Basjes
I see several @SuppressWarnings("rawtypes"), can you reproduce the problem also with fully typed code (without rawtypes)?
(In reply to Niels Basjes from comment #0)
> Turns out that depending on the ordering of the methods Eclipse either finds
> the code good or bad.
This doesn't sound like a surprise to me. In chained method calls of course a lot depends on the order of methods. Why should it not?
About the warnings: On StackOverflow there are several questions regarding the Builder pattern and inheritance. https://stackoverflow.com/questions/21086417/builder-pattern-and-inheritance https://stackoverflow.com/questions/17164375/subclassing-a-java-builder-class https://stackoverflow.com/questions/10941464/builder-pattern-with-inheritance Some even indicate they have a solution for these warnings but so far I have not been able to get those directions to work without any warnings. If you can indicate how to do that that would be nice for my own project also. About the ordering of the calls: The trick here is that both the end result class and the builder class are passed as generic parameters up the class hierarchy so that all builder related methods can return the correct type. So in the example case of the GrandChild class these three methods in that hierarchy GrandChildBuilder::withColor, ChildBuilder::withSize and Parent::withName must all return the same type which is passed as the parameter BUILDER. In this case that would be a GrandChildBuilder. So because all return the same type the ordering of the methods does not matter. FYI: I found that this pattern is sometimes called the "Curiously recurring template pattern" https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |