ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <>
Subject Re: AW: a problem compiling a Java 5 project with generics
Date Wed, 18 Oct 2006 22:28:39 GMT
Chavdar Botev wrote:
>> Peter Reilly wrote:
>> The original code may be slightly incorrect (my understanding
>> of java generics is not high).
> Ha-ha. I think the original code cannot be slightly incorrect. It is
> either correct or incorrect. ;) It certainly possible that my
> understanding of Java generics is wrong. I come from a C++ templates
> background and although syntactically similar, Java generics and C++
> templates seem to be very different. C++ templates are just fancy
> macros. Java generics are types. Unfortunately, I think that these
> syntactic similarities can often lead to misconceptions and errors.

I dont fully understand generics.

They are only half way to full types, in ways that fail in interesting 

Now, one aspect of C++ 2.0 templates is that they really are macros, so 
bind at compile time to the types. This is why you can do very efficient 
work with integers in STL, without needing boxing/unboxing. You cannot 
do any runtime introspection, and all that stuff in C++ related to run 
time typing is just wierd.

> The problem with the project I posted is the inconsistent behavior. If
> my code is incorrect, that's fine, I'll have to rework it. In this
> case, the compilation should always fail. If the code is correct, the
> compilation should always succeed.
> Anyway, I think I am going to post on the Sun Java problems to try to
> locate where the problem is. Is it in my possibly incorrect
> understanding of Java generics, is it in the java compiler, or is it
> in Ant which puts the destination directory in the classpath?
> As of the previous comments about the value in using Java generics, I
> think the biggest value is not saving some typing. In fact, with the
> lack of typedefs, this saving is rather dubious. I think the biggest
> advantage is that they allow the Java compiler to do a lot of type
> checks at compilation time. In previous versions of Java, you could
> add an Apple to a collection of Oranges and you will not know this
> until you try to retrieve the Apple and type-cast it to an Orange.
> Anything that avoids a runtime error by doing a compile-time check is
> good in my book.

1. I dont like all the extra typing you need everywhere; it makes things 
more verbose. What is wrong with polymorphic type inference?

2. its still trivially easy to add an orange to the hash table of 
apples. The underlying hashmap/table is not protected.

3. there are some 'metatypes' I cannot write. Or they compile, but dont 
work as expected.

This doesnt mean I am not enamoured of java5, its just generics are a 
bit of a disappointment.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message