I have the following code, which I'm using to read each element from an array in turn. I've recently modified it to work with an array of any type, but it no longer works.
When I use it like this, I am told that the constructor ArrayReader<Character>(char) is undefined.
What's going on here? Thanks v much for any help....
[ March 28, 2006: Message edited by: John Wickerson ]
Originally posted by Jeff Albertson:
You are bumping up against a basic limitation of generic types in Java: T doesn't range over primitive types like char. To make your example work, you have to copy your char into a Character. I don't know any method to do that, so just roll up your sleeves and write a loop.
Indeed, this is a horrible limitation, however, generics are not the cause. The existence of both primitive types and arrays is the cause, and as a consequence, generics are unable to achieve this common use case due to the leak of abstraction.
ContractualJ attempts to work around the whole mess of primitives with the net.tmorris.primitives package and the mess of arrays with net.tmorris.sequence. The solution is partially optimal, but as optimal as possible within the constraints of the assumed context (e.g. must compile with a Java compiler is a devastational constraint but one that I choose to impose).
I continually find it astonishing that so many subscribe to the legitimacy of these constructs, albeit suffering consequences of this blind faith often stated at the same time!! ...quite often attribution of the cause to a consequence of the cause, instead of externalising the issue for analysis and deriving the real cause (which sometimes contradicts the belief of the establishment).