I think this is more advice then a question as I think I now understand what the above message is trying to tell me.
Here is the setup:
Ok, so in my mind and Eclipse this all works fine, but line //EEEK fails big time on the command line.
I think basicly what is happening is that javac donst know what E should be, even though it has been told it will extend Record (which is why I think it should work), E is some object that extends Record, toNetSuiteRecord is returning some object that extends Record. It should all be fine.
I think the only way to fix this is to replace EEEK with:
Then provide the required class.
Can anybody offer any better advice?
For the record I am using generics because Record is just a Super type, it dosnt group the generic Record functionality, it is just there for structure, much like a marker interface, so this was the only may I could think of to offer the conversion for the many different sub types of Record I need.
Gavin Tranter wrote:E is some object that extends Record, toNetSuiteRecord is returning some object that extends Record. It should all be fine.
But that doesn't guarantee that toNetSuiteRecord returns the same type of sub-class of Record that E happens to be. What if, say, toNetSuiteRecord returns a SubClassOfRecord, and E is ADifferentSubClassOfRecord? The assignment won't be valid then.
Either your selected solution, or using E super Record instead of E extends Record would make it compile. (I couldn't say which is better - it depends on the rest of the situation).
I thought that E super Record means that E is a super type of Record?
I think you are right in general and I will have to document that as a possibility. However I am only passing in list of one type (ie List<SomeTypeOfRecord>) rather then extends x.
Its a bit of a worry
Gavin Tranter wrote:I thought that E super Record means that E is a super type of Record?
That's right. Thinking like a compiler: if all you know about a return value is that it's a sub-type of X, then the only reference you can safely assign it to is an X, or any super-type of X.
Edit: perhaps you don't actually need the generic types on the return value? In toNetSuiteRecord, for example, I'm not sure what the R parameter is gaining you. Pretty much anything that calls that method is going to have to assume a Record is getting returned anyway.