Shridhar Raghavan wrote:
Thanks for the post. But i haven't quite got what you tried to put across. Both code seem to declare that they return a list of numbers.
What is the difference?
Shridhar Raghavan wrote:
The first one means: The code calling getNumbers() will know exactly what type the List will be of
and
The code calling the second example doesn't care about the exact type of the list. "It knows the type will extend Number"
Both statements say the same thing.
Shridhar Raghavan wrote:
Shridhar Raghavan wrote:
Shridhar Raghavan wrote:
Shridhar Raghavan wrote:I was trying to figure out the intended behavior of generic structures. Now if i just used MyDataStructure<T> extends ArrayList<E>, i get a compilation error stating the type parameter is undefined. What is the reason behind this? Actually sounds ridiculous to me as well, but why can't i change the parameter type name. How would hypothethically, having the ability to create "MyDataStructure<T> extends ArrayList<E>" break any code?
Shridhar Raghavan wrote:Also could someone just help out with my last post on generics dated "Tuesday, February 22, 2011 00:19:39". The part directed towards Henry Wong.
Does that make sense?
If you're using the ? wildcard this gets a bit more complicated, but don't worry about that until you fully understand how it works without wildcards.
And Joachim Rohde posted a link to Angelika Langer's website, which is another good resource.Matthew Brown wrote: . . .
One good resource was posted above, and there's also the official Java Generic Tutorial. . . .
Consider Paul's rocket mass heater. |