Mike Simmons wrote:Unless you're deliberately trying to mess with people's expectations.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Mike Simmons wrote:Or, of course, you could specify V when you declare the type of dataMap. Your code is behaving as if you've written
But what you need is
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Mike Simmons wrote:Where is the variable dataMap declared? Not the class DataMap, but the variable dataMap. It doesn't seem to be shown above, and I'm pretty sure that's where the problem lies.
salvin francis wrote:
Mike Simmons wrote:Unless you're deliberately trying to mess with people's expectations.
Go easy friend its his first post
Welcome to javaranch James Gary
You can edit your post any time using the edit button...
Mike Simmons wrote:Oh, also there's a fairly well-established convention in Java that method names and variable names should begin with lowercase, while class and interface names begin in uppercase. Violating this tends to cause unnecessary confusion in your readers, and possibly irritation with or disrespect for the author of the code. So the method ConversionElements() should probably be conversionElements(). Unless you're deliberately trying to mess with people's expectations.
Mike Simmons wrote:Or, of course, you could specify V when you declare the type of dataMap. Your code is behaving as if you've written
But what you need is
Or replace ConversionElement with some other specific subtype if that's preferable. The problem is that if you omit the generic type entirely, the compiler
does not do the reasonable thing and infer that V must at least be a ConversionElement. Instead, it uses erasure, which basically means all generic type information is lost, and V is replaced with Object - hence the compiler error you observed.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:Because when you declare your variable as "DataMap dataMap", all generic information is lost. conversionElements() now no longer returns Collection<V> but Collection - no generic type there. Not even ConversionElement, the root of the allowed generic types. And you can only retrieve elements as Object from any raw collection.
salvin francis wrote:
Mike Simmons wrote:Unless you're deliberately trying to mess with people's expectations.
Go easy friend its his first post
Welcome to javaranch James Gary
You can edit your post any time using the edit button...