author didn't understand how Java works?
05 Sep 2011, 08:59
Jeroen Wenting (2 posts)
Page 90: “Multimethods fix a problem in Java.9 Take a look at the following Java code that uses Generics. lst refers to an instance of ArrayList, and col, which is of type Collection, is referring to the same instance. You added three elements to lst and removed one."
He claims the behaviour shown is a problem in Java. It isn’t, it’s a problem with the author’s lack of understanding of the APIs he’s using. If he’d read the API documentation, he’d have understood that Collection.remove(Object o) does NOT remove the element at an index, but the specific element passed in as an argument. As that element doesn’t exist in the collection, nothing is removed. ArrayList overrides this method with another one that allows removing elements at a specified index.
That’s no error in Java. It’s a way in which Java is just different from Groovy.
|You must be logged in to comment|